<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
    
class Search_global extends CI_Controller 
{
	function __construct()
	{
		parent::__construct();
        if((!check_auth()) ? redirect("/login/auth") : site_url("/home"));
        $this->load->library('mypaging');
	    $this->load->model('sGlobal_model');
        //$this->load->helper('date');
        //echo "ANDI"; exit;
	}
	function coba(){
	   //echo Andi; //exit;
       $this->getView2($this->uri->segment(1),"coba",$data);
       //$this->load->view('search_global/coba');
	}
    //function index(){
    //    $this->getView2($this->uri->segment(1),"coba",$data);
    //}
	/*********************************************************
	**	MODULE SEARCH GLOBAL 							    **
	**	AUTHOR 			: ANDI SISWANTO						**
	**	DATE CREATED	: 16 Juli 2014						**
	*********************************************************/
    
    //DEFAULT SARANA KERJA
    
	function index()
	{
	    //echo "ANDI SISWANTO"; exit;
        $data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
         
	    $saranaKerja="'REQUEST GA', 'REPAIR & MAINTENANCE', 'SURAT IJIN KERJA', 'ACCESS CONTROL', 'OVERTIME', 'LOT PARKIR'";
        //$publicRoom="'MEETING ROOM', 'MAILLING ROOM'";
        //$service="'PAGING INFO', 'SARAN & KELUHAN', 'TRAFFIC','ORDER EQUIPMENT'";
        
        
		$arr['search_by_regional'] = trim($this->input->post('search_by_regional'));
        $arr['search_by_status'] = trim($this->input->post('search_by_status'));
        $arr['search_by_type'] = trim($this->input->post('search_by_type'));

        //$this->mypaging->items_total = $this->setup_model->count_area($arr);
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $saranaKerja);
        $this->mypaging->function_load = "load_page_saranaKerja";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        //$data['list_data'] = $this->setup_model->list_area($arr, $limit);
        $data['list_data'] = $this->sGlobal_model->list_global($arr, $saranaKerja, $limit);
        //$data['list_data_publicRoom'] = $this->sGlobal_model->list_saranaKerja($arr, $publicRoom, $limit);
        //$this->load->view('setup_area/area_list_view', $data);
        
        
       
        //$data['saranaKerja']=$this->sGlobal_model->getSaranaKerjaList($saranaKerja);
        //$data['publicRoom']=$this->sGlobal_model->getPublicRoomList($publicRoom);
        //$data['service']=$this->sGlobal_model->getServiceList($service);
        
        //$this->getView($this->uri->segment(1),$data);
        $this->load->view("header");
        $this->load->view("search_global/search_global",$data);
        $this->load->view("footer");
	}
	
    
	function getView2($P_Menu,$S_Menu, $data)
	{
		//$this->load->view('header');
		if ($data)
		{
		//	var_dump($data);
			$this->load->view($P_Menu.'/'.$S_Menu,$data);
		}
		else
		{
		//	var_dump($data);
			$this->load->view($P_Menu.'/'.$S_Menu);
		}
		//$this->load->view('footer');
	}	
	function getView($P_Menu, $data)
	{
		$this->load->view('header');
		if ($data)
		{
		//	var_dump($data);
			$this->load->view($P_Menu."/".$P_Menu,$data);
		}
		else
		{
		//	var_dump($data);
			$this->load->view($P_Menu."/".$P_Menu);
		}
		$this->load->view('footer');
	}
    
    
    //==========
    function saranaKerja()
	{
        $data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
         
	    $saranaKerja="'REQUEST GA', 'REPAIR & MAINTENANCE', 'SURAT IJIN KERJA', 'ACCESS CONTROL', 'OVERTIME', 'LOT PARKIR'";
        //$publicRoom="'MEETING ROOM', 'MAILLING ROOM'";
        ///$service="'PAGING INFO', 'SARAN & KELUHAN', 'TRAFFIC','ORDER EQUIPMENT'";
        
        
		$arr['search_by_regional'] = trim($this->input->post('search_by_regional'));
        $arr['search_by_status'] = trim($this->input->post('search_by_status'));
        $arr['search_by_type'] = trim($this->input->post('search_by_type'));

        //$this->mypaging->items_total = $this->setup_model->count_area($arr);
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $saranaKerja);
        $this->mypaging->function_load = "load_page_saranaKerja";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        $data['list_data'] = $this->sGlobal_model->list_global($arr, $saranaKerja, $limit);
        
        //$this->getView($this->uri->segment(1),$data);
        
        $this->load->view('search_global/sarana_kerja',$data);
	}
    function load_page_saranaKerja() {
        $saranaKerja="'REQUEST GA', 'REPAIR & MAINTENANCE', 'SURAT IJIN KERJA', 'ACCESS CONTROL', 'OVERTIME', 'LOT PARKIR'";
        //echo $saranaKerja;  
        /*$cek1 = $this->session->flashdata('search_by_regional');
        $cek2 = $this->session->flashdata('search_by_status');
        $cek3 = $this->session->flashdata('search_by_type');
    
        if ($cek1 != '' || $cek2 != '' || $cek3 != '') {
            $arr['search_by_regional'] = trim($this->session->flashdata('search_by_regional'));
            $arr['search_by_status'] = trim($this->session->flashdata('search_by_status'));
            $arr['search_by_type'] = trim($this->session->flashdata('search_by_type'));
        } else {
            $arr['search_by_option'] = trim($this->input->post('search_by_option'));
            $arr['search_by_date_start'] = trim($this->input->post('G_Date1'));
            $arr['search_by_date_end'] = trim($this->input->post('G_Date2'));
            $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));
        }
        */
        $arr['search_by_option'] = trim($this->input->post('search_by_option'));
        $arr['search_by_date_start'] = trim($this->input->post('search_by_date_start'));
        $arr['search_by_date_end'] = trim($this->input->post('search_by_date_end'));
        $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));
        
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $saranaKerja);
        $this->mypaging->function_load = "load_page_saranaKerja";
        $this->mypaging->post_page = trim($this->input->post("page"));
        $this->mypaging->post_ipp = trim($this->input->post("ipp"));
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        //echo $limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1; //2-1 * 10+1=11   3-1 * 10+1=21  merupakan nilai awal hal berikutnya
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();
        
        //echo $data['page']; exit;
        $data['list_data'] = $this->sGlobal_model->list_global($arr, $saranaKerja, $limit);
        //var_dump($data['list_data']);
        $this->load->view('search_global/saranaKerja_search_view', $data);
    }
    
    function search_saranaKerja() {
        $saranaKerja="'REQUEST GA', 'REPAIR & MAINTENANCE', 'SURAT IJIN KERJA', 'ACCESS CONTROL', 'OVERTIME', 'LOT PARKIR'";
        $arr['search_by_option'] = trim($this->input->post('search_by_option'));
        $arr['search_by_date_start'] = trim($this->input->post('search_by_date_start'));
        $arr['search_by_date_end'] = trim($this->input->post('search_by_date_end'));
        $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));
        
        //var_dump($arr); exit;
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $saranaKerja);
        $this->mypaging->function_load = "load_page_saranaKerja";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        //echo $limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        $data['list_data'] = $this->sGlobal_model->list_global($arr, $saranaKerja, $limit);
        //var_dump($data['list_data']);
        $this->load->view('search_global/saranaKerja_search_view', $data);
    }
    
    //==========
    function publicRoom()
	{
        $data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
         
	    //$saranaKerja="'REQUEST GA', 'REPAIR & MAINTENANCE', 'SURAT IJIN KERJA', 'ACCESS CONTROL', 'OVERTIME', 'LOT PARKIR'";
        $publicRoom="'MEETING ROOM', 'MAILLING ROOM'";
        ///$service="'PAGING INFO', 'SARAN & KELUHAN', 'TRAFFIC','ORDER EQUIPMENT'";
        
        
		$arr['search_by_regional'] = trim($this->input->post('search_by_regional'));
        $arr['search_by_status'] = trim($this->input->post('search_by_status'));
        $arr['search_by_type'] = trim($this->input->post('search_by_type'));

        //$this->mypaging->items_total = $this->setup_model->count_area($arr);
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $publicRoom);
        $this->mypaging->function_load = "load_page_publicRoom";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        $data['list_data'] = $this->sGlobal_model->list_global($arr, $publicRoom, $limit);
        
        //$this->getView($this->uri->segment(1),$data);
        
        $this->load->view('search_global/public_room',$data);
	}
    function load_page_publicRoom() {
        $publicRoom="'MEETING ROOM', 'MAILLING ROOM'";
        $arr['search_by_option'] = trim($this->input->post('search_by_option'));
        $arr['search_by_date_start'] = trim($this->input->post('search_by_date_start'));
        $arr['search_by_date_end'] = trim($this->input->post('search_by_date_end'));
        $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));

        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $publicRoom);
        $this->mypaging->function_load = "load_page_publicRoom";
        $this->mypaging->post_page = trim($this->input->post("page"));
        $this->mypaging->post_ipp = trim($this->input->post("ipp"));
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1; //2-1 * 10+1=11   3-1 * 10+1=21  merupakan nilai awal hal berikutnya
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();
        
        //echo $data['page']; exit;
        $data['list_data'] = $this->sGlobal_model->list_global($arr, $publicRoom, $limit);
        //var_dump($data['list_data']);exit;
        $this->load->view('search_global/publicRoom_search_view', $data);
    }
    
    function search_publicRoom() {
        $publicRoom="'MEETING ROOM', 'MAILLING ROOM'";
        //echo $publicRoom;
        $arr['search_by_option'] = trim($this->input->post('search_by_option'));
        $arr['search_by_date_start'] = trim($this->input->post('search_by_date_start'));
        $arr['search_by_date_end'] = trim($this->input->post('search_by_date_end'));
        $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));
        
        //var_dump($arr); 
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $publicRoom);
        $this->mypaging->function_load = "load_page_publicRoom";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        //echo $limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        $data['list_data'] = $this->sGlobal_model->list_global($arr, $publicRoom, $limit);
        //var_dump($data['list_data']);
        $this->load->view('search_global/publicRoom_search_view', $data);
    }
    //======
    function services()
	{
        $data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
         
	    //$saranaKerja="'REQUEST GA', 'REPAIR & MAINTENANCE', 'SURAT IJIN KERJA', 'ACCESS CONTROL', 'OVERTIME', 'LOT PARKIR'";
        //$publicRoom="'MEETING ROOM', 'MAILLING ROOM'";
        $service="'PAGING INFO', 'SARAN & KELUHAN', 'TRAFFIC','ORDER EQUIPMENT'";
        
        
		$arr['search_by_regional'] = trim($this->input->post('search_by_regional'));
        $arr['search_by_status'] = trim($this->input->post('search_by_status'));
        $arr['search_by_type'] = trim($this->input->post('search_by_type'));

        //$this->mypaging->items_total = $this->setup_model->count_area($arr);
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $service);
        $this->mypaging->function_load = "load_page_services";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        $data['list_data'] = $this->sGlobal_model->list_global($arr, $service, $limit);
        
        //$this->getView($this->uri->segment(1),$data);
        
        $this->load->view('search_global/services',$data);
	}
    function load_page_services() {
        $service="'PAGING INFO', 'SARAN & KELUHAN', 'TRAFFIC','ORDER EQUIPMENT'";
        $arr['search_by_option'] = trim($this->input->post('search_by_option'));
        $arr['search_by_date_start'] = trim($this->input->post('search_by_date_start'));
        $arr['search_by_date_end'] = trim($this->input->post('search_by_date_end'));
        $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));
        
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $service);
        $this->mypaging->function_load = "load_page_services";
        $this->mypaging->post_page = trim($this->input->post("page"));
        $this->mypaging->post_ipp = trim($this->input->post("ipp"));
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1; //2-1 * 10+1=11   3-1 * 10+1=21  merupakan nilai awal hal berikutnya
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();
        
        //echo $data['page']; exit;
        $data['list_data'] = $this->sGlobal_model->list_global($arr, $service, $limit);
        //var_dump($data['list_data']);exit;
        $this->load->view('search_global/services_search_view', $data);
    }
    function search_services() {
        $service="'PAGING INFO', 'SARAN & KELUHAN', 'TRAFFIC','ORDER EQUIPMENT'";
        $arr['search_by_option'] = trim($this->input->post('search_by_option'));
        $arr['search_by_date_start'] = trim($this->input->post('search_by_date_start'));
        $arr['search_by_date_end'] = trim($this->input->post('search_by_date_end'));
        $arr['search_by_keyword'] = trim($this->input->post('search_by_keyword'));
        
        //var_dump($arr); 
        $this->mypaging->items_total = $this->sGlobal_model->count_global($arr, $service);
        $this->mypaging->function_load = "load_page_services";
        $this->mypaging->post_page = 1;
        $this->mypaging->post_ipp = 10;
        $this->mypaging->mid_range = 5;
        $this->mypaging->paginate();
        $limit = $this->mypaging->limit;
        //echo $limit;
        $data['page'] = (($this->input->post("page") - 1) * $this->input->post("ipp")) + 1;
        $data['paging'] = $this->mypaging->display_pages();
        $data['jump_page'] = $this->mypaging->display_jump_menu();
        $data['ipp'] = $this->mypaging->display_items_per_page();

        $data['list_data'] = $this->sGlobal_model->list_global($arr, $service, $limit);
        //var_dump($data['list_data']);
        $this->load->view('search_global/services_search_view', $data);
    }
    
    
    // REVISI DI SINI, KARENA BUKAN CUMA ACCESS CONTROL UNTUK APPROVE ATASAN========================================================================
    function approve_manager(){
        $data['cRequestNo']=$this->input->post('cRequestNo');
        $data['cType']=$this->input->post('cType');
        $data['cTab']=$this->input->post('cTab');
        $cRequestNo=$data['cRequestNo'];
        $cType=$data['cType'];
        $cTab=$data['cTab'];
        //ambil session
        $CI =& get_instance();
        $data['sesName']=$CI->session->userdata('login')['name'];
        $data['sesJob']=$CI->session->userdata('login')['job'];
        $data['sesNik']=$CI->session->userdata('login')['nik'];
        $data['sesJobPosition']=$CI->session->userdata('login')['jobposition'];
        $data['sesOrg']=$CI->session->userdata('login')['org'];
        //var_dump($data); exit;
        
        switch($cTab){
            case 'saranaKerja':
                switch($cType){
                    case 'ACCESS CONTROL':
                        $data['getDetail']=$this->sGlobal_model->getDetail($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getFloor($cRequestNo);
                        $data['getFloor2']=$this->sGlobal_model->getFloor2($cRequestNo);
                        $this->load->view('search_global/approve_manager',$data);
                        break;
                    case 'SURAT IJIN KERJA':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditSik($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2EditSik($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getFloorEditSik();
                        $this->load->view('search_global/app_mgrSrnKrjSik',$data); break;
        				break;
        			case 'REQUEST GA':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditReq($cRequestNo);
                        $this->load->view('search_global/app_mgrSrnKrjReq',$data);
        				break;
        			case 'OVERTIME':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditOvt($cRequestNo);
                        $data['getDetailVendor']=$this->sGlobal_model->getDetailEditOvtVendor($cRequestNo);
                        $data['getNik']=$this->sGlobal_model->getNik();
                        $data['getAtasanNik']=$this->sGlobal_model->getAtasanNik();
                        $data['getVendor']=$this->sGlobal_model->getVendor();
                        $data['getLantai']=$this->sGlobal_model->getLantai();
                        $this->load->view('search_global/app_mgrSrnKrjOvt',$data);
        				break;
        			case 'LOT PARKIR':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditPrk($cRequestNo);
                        $this->load->view('search_global/app_mgrSrnKrjPrk',$data); 	
        				break;
        			case 'REPAIR & MAINTENANCE':
                        $data['getDetail']=$this->sGlobal_model->appMgrSrnKrjRmDetail($cRequestNo);
                        $this->load->view('search_global/app_mgrSrnKrjRm',$data);
        				break;
                }
                 
                break;
            case 'publicRoom':
                switch($cType){
                    case 'MAILLING ROOM':
                        $data['getDetail']=$this->sGlobal_model->getDetailPublicRoom($cRequestNo);
                        //$data['getFloor']=$this->sGlobal_model->getFloor($cRequestNo);
                        //$data['getFloor2']=$this->sGlobal_model->getFloor2($cRequestNo);
                        $this->load->view('search_global/approve_manager_publicRoom',$data);
                        break;
                    case 'MEETING ROOM':
                        break;
                } 
                break;
            case 'services':
                switch($cType){
                    case 'PAGING INFO':
                        $data['getDetail']=$this->sGlobal_model->getDetailPagingInfo($cRequestNo);
                        $this->load->view('search_global/app_mgrServPag',$data);
                        break;
                    case 'SARAN & KELUHAN':
                        break;
                    case 'ORDER EQUIPMENT':
                        break;
                }
                break;            
        }
    }
    //===============================================================APPROVE MANAGER 14/10/2014=========================================================
    function approve_managerSave(){
        $arr['pCtrlID']=$this->input->post('pCtrlID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pComment']=$this->input->post('pComment');
        $arr['pAccesNo']=$this->input->post('pAccesNo');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        if(!empty($arr['pApproval'])){
            $this->sGlobal_model->appManagerSave($arr);	
            send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg);
        }
    }
    function approve_managerPublicRoomSave(){
        $arr['pDmrID']=$this->input->post('pDmrID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pComment']=$this->input->post('pComment');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        
        if(!empty($arr['pApproval'])){ 
            $this->sGlobal_model->appManagerPublicRoomSave($arr);
            $msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
    		send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg);	
        }
    }
    function app_mgrSrnKrjReqSave(){
        $pCtrlID=$this->input->post('pCtrlID');
        $pApproval=$this->input->post('pApproval');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $arr['pCtrlID']=$this->input->post('pCtrlID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        //$arr['pComment']=$this->input->post('pComment');
        //$arr['pAccesNo']=$this->input->post('pAccesNo');
        
        if(!empty($pApproval)){	
            $this->sGlobal_model->appMgrSrnKrjReqSave($arr);
            //$stmt1	=	"update fm_req_head set req_atasan_app='$pApproval', req_atasan_app_date=sysdate where req_id='$pReqId'";
    		if($pApproval == 'Y') {
    			$msg = "FM : Order No $pCtrlID sudah di approve oleh Atasan.";
    		}
            else {
    			$msg = "FM : Order No $pCtrlID tidak di approve oleh Atasan.";
    		}
    		
    		$msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
            //echo $msisdn;  
    		send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg);
    	}
    }
    function app_mgrSrnKrjRmSave(){
        $pCtrlID=$this->input->post('pCtrlID');
        $pApproval=$this->input->post('pApproval');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $pComment=$this->input->post('pComment');
        $arr['pCtrlID']=$this->input->post('pCtrlID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        $arr['pComment']=$this->input->post('pComment');
        
        if(!empty($pApproval)){	
            $this->sGlobal_model->appMgrSrnKrjRmSave($arr);
    		if($pApproval == 'Y') {
    			$msg = "FM : Order No $pCtrlID sudah di approve oleh Atasan.";
    		}
            else {
    			$msg = "FM : Order No $pCtrlID tidak di approve oleh Atasan.";
    		}
    		
    		$msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
    		send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg);
    	}
    }
    function app_mgrSave(){
        $pCTab=$this->input->post('pCTab');
        $pCType=$this->input->post('pCType');
        $pCtrlID=$this->input->post('pCtrlID');
        $pApproval=$this->input->post('pApproval');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $pComment=$this->input->post('pComment');
        $arr['pCTab']=$this->input->post('pCTab');
        $arr['pCType']=$this->input->post('pCType');
        $arr['pCtrlID']=$this->input->post('pCtrlID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        $arr['pComment']=$this->input->post('pComment');
        
        //var_dump($arr); exit; 
        if(!empty($pApproval)){	        
            switch($pCTab){
                case "saranaKerja":
                    switch($pCType){
                        case "SURAT IJIN KERJA":
                            $this->sGlobal_model->appMgrSrnKrjSikSave($arr);
                            break;
                        case 'ACCESS CONTROL':
                            break;
            			case 'REQUEST GA':
            				break;
            			case 'OVERTIME':
                            $this->sGlobal_model->appMgrSrnKrjOvtSave($arr);
            				break;
            			case 'PAGING INFO':
            				break;
            			case 'ACCESS CONTROL':
            				break;
            			case 'LOT PARKIR':	
                            $this->sGlobal_model->appMgrSrnKrjPrkSave($arr);
            				break;
            			case 'REPAIR & MAINTENANCE':
            				break;
                    }
                    break;
                case "publicRoom":
                    break;
                case "services":
                    switch($pCType){
                        case "PAGING INFO":
                            $this->sGlobal_model->appMgrServPagSave($arr);
                            break;
                        case "SARAN & KELUHAN":
                            break;
                        case "ORDER EQUIPMENT":
                            break;    
                    }
                    break;    
            }
            
            if($pApproval == 'Y') {
    			$msg = "FM : Order No $pCtrlID sudah di approve oleh Atasan.";
    		}
            else {
    			$msg = "FM : Order No $pCtrlID tidak di approve oleh Atasan.";
    		}
    		$msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
    		//send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg);
        }
    }
    //===============================================================APPROVE MANAGER END 16/10/2014=========================================================
    //===============================================================APPROVE GA START 17/10/2014=========================================================
    function approve_gaSave(){
        $arr['pCtrlID']=$this->input->post('pCtrlID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pComment']=$this->input->post('pComment');
        if(!empty($arr['pApproval'])){ 
            $this->sGlobal_model->appGaSave($arr);	
            
            if($pApproval == 'Y') {
    			$msg = "FM : Order No $pCtrlID sudah di approve oleh GA.";
    		}
            else {
    			$msg = "FM : Order No $pCtrlID tidak di approve oleh GA.";
    		}
    		$msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
            send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg);
        }
    }
    function approve_gaPublicRoomSave(){
        $arr['pDmrID']=$this->input->post('pDmrID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pComment']=$this->input->post('pComment');
        $arr['pDmKurir']=$this->input->post('pDmKurir');
        $arr['pDmBerat']=$this->input->post('pDmBerat');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        $pCtrlID=$this->input->post('pDmrID');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $pApproval=$this->input->post('pApproval');
        $msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
        $arr['msisdn']=$msisdn;
        
        //var_dump($arr);exit;
        if(!empty($arr['pApproval'])){ 
            $this->sGlobal_model->appGaPublicRoomSave($arr);
            
            if($pApproval == 'Y') {
    			$msg = "FM : Order No $pCtrlID sudah di approve oleh GA.";
    		}
            else {
    			$msg = "FM : Order No $pCtrlID tidak di approve oleh GA.";
    		}
    		
            //send_sms($msisdn, $msg);
            send_sms('081286405259', $msg.$msisdn);	 //Andi
        }
    }
    function approve_gaServicesSave(){
        $CI =& get_instance();
        $sesNik=$CI->session->userdata('login')['nik'];
        $arr['sesName']=$CI->session->userdata('login')['name'];
        $arr['sesJob']=$CI->session->userdata('login')['job'];
        $arr['sesNik']=$CI->session->userdata('login')['nik'];
        
        $arr['pOrderID']=$this->input->post('pOrderID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pComment']=$this->input->post('pComment');
        $arr['pWareItemId']=$this->input->post('pWareItemId');
        $arr['pCheck']=$this->input->post('pCheck');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        
        $pOrderID    	=  $arr['pOrderID'];
        $pApproval    	=  $arr['pApproval'];
        $pComment		=  $arr['pComment'];
        $pWareItemId	=  $arr['pWareItemId'];
        $pCheck		    =  $arr['pCheck'];
        
        $msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
        $arr['msisdn']=$msisdn;
        //var_dump($pWareItemId);var_dump($pCheck);
        //exit;
        if(!empty($pApproval)){ 
            //$this->sGlobal_model->appGaPublicRoomSave($arr);	
            if($pApproval=='N'){
                $this->sGlobal_model->appGaServicesSave($arr);
                $this->sGlobal_model->appGaServicesSaveN($arr);
                //$upd1 = "update FM_ORDER_DETAIL set ORDER_DET_STATUS  = 'N' where ORDER_ID = '$pOrderID'";
            }
            else{
                $this->sGlobal_model->appGaServicesSave($arr);
                $barangPesanan=$this->sGlobal_model->appGaServicesCekBarangPesanan($pOrderID);
                
                $i=0;
                foreach($barangPesanan as $row1){
                    $vWareId = $row1['WAREHOUSE_ID'];
                    $vQty	 = $row1['ORDER_DET_QTY'];
                    //echo $vWareId;
                    //echo $pCheck[$i];
                    //echo $pWareItemId[$i];
                    if(!empty($pCheck[$i]) && $pCheck[$i] == 'Y') {
                        $barangPesananQty=$this->sGlobal_model->appGaServicesCekBarangPesananQty($pOrderID,$pWareItemId[$i]);
                        //$stockWarehouse=$this->sGlobal_model->appGaServicesCekStockWarehouse($pWareItemId[$i]);
                        foreach($barangPesananQty as $e){
                            $pQty = $e['ORDER_DET_QTY'];
                        }
                        //echo $i."/".$pWareItemId[$i]." ";
                        $this->sGlobal_model->appGaServicesUpdateJumlahBarangWarehouse($pQty,$pWareItemId[$i]); 
                        /*foreach($stockWarehouse as $stk){
                            $stkAll=$stk['WAREHOUSE_ITEM_QTY'];
                            $stkIn=$stk['WAREHOUSE_ITEM_QTY_IN'];
                            $stkOut=$stk['WAREHOUSE_ITEM_QTY_OUT'];
                        //echo $pQty;
                        /*
                        if($pQty>$stkIn){ //Jika Jumlah Permintaan melebihi jumlah Stock Gudang
                            ?>
                            <script>
                            alert("Jumlah Order Melebihi Stock (Kemungkinan Ada Admin Lain Yang Approve Duluan)\n"+"order="+<?php echo $stkIn;?>+"Stock="+<?php echo $stkAll;?>);
                            return false;
                            </script>
                            <?php
                        }
                        else{
                            */   
                        //}
                    }
                    else{
                        $this->sGlobal_model->appGaServicesSaveN2($pOrderID,$pWareItemId[$i]);
                        //echo "B";
                    }
                    $i++;
                }
            }
            if($pApproval == 'Y') {
    			$msg = "FM : Order No $pOrderID sudah di approve oleh GA.";
    		}
            else {
    			$msg = "FM : Order No $pOrderID tidak di approve oleh GA.";
    		}
    		
    		//send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg); //ardha
            //send_sms('081286405259', $msg.$msisdn); //Andi
        }
    }
    function app_gaSave(){
        $CI =& get_instance();
        $sesNik=$CI->session->userdata('login')['nik'];
        $arr['sesName']=$CI->session->userdata('login')['name'];
        $arr['sesJob']=$CI->session->userdata('login')['job'];
        $arr['sesNik']=$CI->session->userdata('login')['nik'];
        
        $pCTab=$this->input->post('pCTab');
        $pCType=$this->input->post('pCType');
        $pCtrlID=$this->input->post('pCtrlID');
        $pApproval=$this->input->post('pApproval');
        $pNikRequestBy=$this->input->post('pNikRequestBy');
        $pComment=$this->input->post('pComment');
        $arr['pCTab']=$this->input->post('pCTab');
        $arr['pCType']=$this->input->post('pCType');
        $arr['pCtrlID']=$this->input->post('pCtrlID');
        $arr['pApproval']=$this->input->post('pApproval');
        $arr['pNikRequestBy']=$this->input->post('pNikRequestBy');
        $arr['pComment']=$this->input->post('pComment');
        
        $msisdn = $this->sGlobal_model->getMsisdn($pNikRequestBy);
        $arr['msisdn']=$msisdn;
        //var_dump($arr); exit; 
        if(!empty($pApproval)){	        
            switch($pCTab){
                case "saranaKerja":
                    switch($pCType){
                        case "SURAT IJIN KERJA": //Done
                            $this->sGlobal_model->appGaSrnKrjSikSave($arr);
                            break;
            			case 'REQUEST GA': //Done
                            $arr['pBudget']=$this->input->post('pBudget');
                            $this->sGlobal_model->appGaSrnKrjReqSave($arr);
            				break;
            			case 'OVERTIME': //Done
                            $this->sGlobal_model->appGaSrnKrjOvtSave($arr);
            				break;
            			case 'PAGING INFO':
            				break;
            			case 'ACCESS CONTROL': //Done on other side
            				break;
            			case 'LOT PARKIR':	//Done
                            $this->sGlobal_model->appGaSrnKrjPrkSave($arr);
            				break;
            			case 'REPAIR & MAINTENANCE': //Done
                            $this->sGlobal_model->appGaSrnKrjRmSave($arr);
            				break;
                    }
                    break;
                case "publicRoom":
                    switch($pCType){
                        case "MAILLING ROOM": //Done by other side
                            break;
                        case "MEETING ROOM":
                            $pCek=$this->input->post('pCek');
                            $pWareItemId=$this->input->post('pWareItemId');
                            $arr['pCek']=$this->input->post('pCek');
                            $arr['pWareItemId']=$this->input->post('pWareItemId');
                            //var_dump($arr); //exit; 
                            $this->sGlobal_model->appGaPubRomMeetSave($arr);
                            if($pApproval == 'Y') {
                        	    $i=0;
                                $x=0;
                                $getdetItem=$this->sGlobal_model->appGaPubRomMeetSelect1($pCtrlID);
                                
                                foreach($getdetItem as $row1){ //Hanya mengulang sebanyak order item, bisa digantikan juga dengan pJumlahI dari post
                                    $vWareId = $row1['WAREHOUSE_ID'];
                        			$vQty	 = $row1['ROOMD_QTY'];
                                    if(!empty($pCek[$x])&&$pCek[$x]=='Y') { 
                        					//$getdet=$this->sGlobal_model->appGaPubRomMeetSelect2($pCtrlID,$pWareItemId[$x]); //aslinya yang ini, cuman aneh pake wareItemId
                                            //pake ini aja, lebih work wareId
                                            $getdet=$this->sGlobal_model->appGaPubRomMeetSelect2($pCtrlID,$vWareId); //nilai vWareId=nilai wareItemId jika nilai wareItemId di from berasal dari WarehouseId bukan dari roomId
                                            foreach($getdet as $e){
                                                $pQty = $e['ROOMD_QTY'];
                                            }
                                            //echo $pQty;
                                            $upd1=$this->sGlobal_model->appGaPubRomMeetUpdate1($pQty,$pWareItemId[$x]); //Warehouse In-Qty, Out+Qty
                        			}
                                    else {
                        			        $upd1=$this->sGlobal_model->appGaPubRomMeetUpdate2($pCtrlID,$pWareItemId[$x]); //ganti room_status menjadi N
                        			}
                        			
                        			$i=$i+1;
                                    $x++;
                                }
                        	} 
                            else {
                                $stmt1=$this->sGlobal_model->appGaPubRomMeetDelete1($pCtrlID); //delete from FM_MEETING_ROOM_DET_PR
                                $stmt2=$this->sGlobal_model->appGaPubRomMeetDelete2($pCtrlID); //delete from FM_MEETING_ROOM_DET
                                //$stmt3=$this->sGlobal_model->appGaPubRomMeetDelete3($pCtrlID); //delete from FM_MEETING_ROOM, tp kenapa harus didelete kalo sudah di X statusnya
                                //delete lah hanya jika database penuh
                        	}
                            break;    
                    }
                    break;
                case "services":
                    switch($pCType){
                        case "PAGING INFO":
                            $this->sGlobal_model->appGaServPagSave($arr);
                            break;
                        case "SARAN & KELUHAN":
                            $arr['pFollowUp']=$this->input->post('pFollowUp');
                            //var_dump($arr); exit;
                            if(!empty($pFollowUp)){
                                $this->sGlobal_model->appGaServSarKelSaveY($arr); //Kenapa jika follow Up kosong, terisi Y   
                            }
                            else{
                                $this->sGlobal_model->appGaServSarKelSave($arr);
                            }
                            break;
                        case "ORDER EQUIPMENT": //Done by other side
                            break;
                        case "TRAFFIC": //Ga perlu
                            break;    
                    }
                    break;    
            }
            
            if($pApproval == 'Y') {
    			$msg = "FM : Order No $pCtrlID sudah di approve oleh GA.";
    		}
            else {
    			$msg = "FM : Order No $pCtrlID tidak di approve oleh GA.";
    		}
    		
    		//send_sms($msisdn, $msg);
            //send_sms('081219395711', $msg); //ardha
            //send_sms('081286405259', $msg.$msisdn); //Andi
        }
    }
    //===============================================================APPROVE GA END ?/10/2014=========================================================
    
    
    
    
    function approve_ga(){
        $data['pReqForNik']=$this->input->post('pReqForNik');
        $data['cRequestNo']=$this->input->post('cRequestNo');
        $data['cType']=$this->input->post('cType');
        $data['cTab']=$this->input->post('cTab');
        $cRequestNo=$data['cRequestNo'];
        $cType=$data['cType'];
        $cTab=$data['cTab'];
        //ambil session
        $CI =& get_instance();
        $data['sesName']=$CI->session->userdata('login')['name'];
        $data['sesJob']=$CI->session->userdata('login')['job'];
        $data['sesNik']=$CI->session->userdata('login')['nik'];
		$data['sesJobPosition']=$CI->session->userdata('login')['jobposition'];
        $data['sesOrg']=$CI->session->userdata('login')['org'];
        
        //var_dump($data); exit;
        
        switch($cTab){
            case 'saranaKerja':
                switch($cType){
                    case 'ACCESS CONTROL': //DONE
                        $data['getDetail']=$this->sGlobal_model->getDetailGa($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getFloorGa($cRequestNo);
                        $data['getFloor2']=$this->sGlobal_model->getFloor2Ga($cRequestNo);
                        $this->load->view('search_global/approve_ga',$data); 
                        break;
                    case 'SURAT IJIN KERJA': //DONE
                        $data['getDetail']=$this->sGlobal_model->getDetailEditSik($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2EditSik($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getFloorEditSik();
                        $this->load->view('search_global/app_gaSrnKrjSik',$data); break;
        				break;
        			case 'REQUEST GA': //DONE
                        $data['getDetail']=$this->sGlobal_model->getDetailEditReq($cRequestNo);
                        $this->load->view('search_global/app_gaSrnKrjReq',$data);
        				break;
        			case 'OVERTIME': //DONE
                        $data['getDetail']=$this->sGlobal_model->getDetailEditOvt($cRequestNo);
                        $data['getDetailVendor']=$this->sGlobal_model->getDetailEditOvtVendor($cRequestNo);
                        $data['getNik']=$this->sGlobal_model->getNik();
                        $data['getAtasanNik']=$this->sGlobal_model->getAtasanNik();
                        $data['getVendor']=$this->sGlobal_model->getVendor();
                        $data['getLantai']=$this->sGlobal_model->getLantai();
                        $this->load->view('search_global/app_gaSrnKrjOvt',$data);
        				break;
        			case 'PAGING INFO':
        				break;
        			case 'LOT PARKIR': //DONE
                        $data['getDetail']=$this->sGlobal_model->getDetailEditPrk($cRequestNo);
                        $this->load->view('search_global/app_gaSrnKrjPrk',$data);
        				break;
        			case 'REPAIR & MAINTENANCE': //DONE
                        $data['getDetail']=$this->sGlobal_model->appMgrSrnKrjRmDetail($cRequestNo);
                        $this->load->view('search_global/app_gaSrnKrjRm',$data);
        				break;    
                }
                break;
            case 'publicRoom':
                switch($cType){
                    case 'MAILLING ROOM': //DONE
                        $data['getDetail']=$this->sGlobal_model->getDetailPublicRoomGa($cRequestNo);
                        foreach($data['getDetail'] as $rowIn){
                            $vcouriertype = $rowIn['DMR_COURIER_TYPE'];
                            $vRecieveDate = $rowIn['DMR_RECIEVE_DATE'];
                        }
                        if ($vcouriertype == "DOM" || $vcouriertype == "INT") {
                            $data['getKurir']=$this->sGlobal_model->getKurirPublicRoomGa($vcouriertype);
                        }
                        else{
                            $data['getKurir']=$this->sGlobal_model->getKurir2PublicRoomGa($vRecieveDate);
                        }
                        $this->load->view('search_global/approve_ga_publicRoom',$data); 
                        break;
                    case 'MEETING ROOM':
                        $data['getDetail']=$this->sGlobal_model->getDetailMeetingRoomGa($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetailMeetingRoomGa2($cRequestNo);
                        $this->load->view('search_global/app_gaPubRomMeet',$data);
                        break;
                }
                break;
            case 'services':
                switch($cType){
                    case 'ORDER EQUIPMENT':
                        $data['getDetail']=$this->sGlobal_model->getDetailServicesGa($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2ServicesGa($cRequestNo);
                        //$data['getFloor2']=$this->sGlobal_model->getFloor2($cRequestNo);
                        $this->load->view('search_global/approve_ga_services',$data);
                        break;
                    case 'SARAN & KELUHAN':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditSarKel($cRequestNo);
                        $data['getType']=$this->sGlobal_model->getDetailEditSarKel2();
                        $this->load->view('search_global/app_gaServSarKel',$data);
                        break;
                    case 'PAGING INFO':
                        $data['getDetail']=$this->sGlobal_model->getDetailPagingInfo($cRequestNo);
                        $this->load->view('search_global/app_gaServPag',$data);
                        break;
                    case 'TRAFFIC':
                        break;
                }       
                break;     
        }
    }
    
    
    function closing_req(){
        $data['cRequestNo']=$this->input->post('cRequestNo');
        $data['cType']=$this->input->post('cType');
        $data['cTab']=$this->input->post('cTab');
        $cRequestNo=$data['cRequestNo'];
        $cType=$data['cType'];
        $cTab=$data['cTab'];
        //ambil session
        $CI =& get_instance();
        $data['sesName']=$CI->session->userdata('login')['name'];
        $data['sesJob']=$CI->session->userdata('login')['job'];
        $data['sesNik']=$CI->session->userdata('login')['nik'];
		$data['sesJobPosition']=$CI->session->userdata('login')['jobposition'];
        $data['sesOrg']=$CI->session->userdata('login')['org'];
        //var_dump($data); exit;
        
        switch($cTab){
            
            case 'saranaKerja':
                //$this->load->view('search_global/approve_ga',$data); 
                switch($cType){
                    case 'REQUEST GA':
                        $data['getDetail']=$this->sGlobal_model->getDetailCloseSrnKrjReq($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2CloseSrnKrjReq($cRequestNo);
                        $data['getDetail3']=$this->sGlobal_model->getDetail3CloseSrnKrjReq($cRequestNo);
                        $data['getDetail4']=$this->sGlobal_model->getDetail4CloseSrnKrjReq($cRequestNo);
                        $data['getDetail5']=$this->sGlobal_model->getDetail5CloseSrnKrjReq($data);
                        if(!empty($cRequestNo)){
                            foreach($data['getDetail'] as $row){
                                $hReqFloor		= $h["REQ_FLOOR"];
	                            $hReqRbfId		= $h["REQ_RBF_ID"];    
                            }
                            $data['getDetail6']=$this->sGlobal_model->getDetail6CloseSrnKrjReq($hReqFloor);
                            $data['getDetail7']=$this->sGlobal_model->getDetail7CloseSrnKrjReq($hReqFloor,$hReqRbfId);
                        }
                        $this->load->view('search_global/closing_srnKrjReq',$data); break;
                    case 'OVERTIME':
                        //echo $cType; exit;
                        $data['getDetail']=$this->sGlobal_model->getDetailCloseSrnKrjOvt($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2CloseSrnKrjOvt($cRequestNo);
                        $this->load->view('search_global/closing_srnKrjOvt',$data); break;
                    case 'REPAIR & MAINTENANCE':
                        $data['getDetail']=$this->sGlobal_model->appMgrSrnKrjRmDetail($cRequestNo);
                        $this->load->view('search_global/closing_srnKrjRm',$data); break;
                    case 'SURAT IJIN KERJA':
                        $data['getDetail']=$this->sGlobal_model->getDetailCloseSrnKrjSik($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2CloseSrnKrjSik($cRequestNo);
                        $this->load->view('search_global/closing_srnKrjSik',$data); break;
                    case 'ACCESS CONTROL':
                        //echo $sesName;
                        //echo $sesJob; 
                        //exit;
                        $data['getDetail']=$this->sGlobal_model->getDetailCloseSrnKrjAcc($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getFloorCloseSrnKrjAcc($cRequestNo);
                        $data['getFloor2']=$this->sGlobal_model->getFloor2CloseSrnKrjAcc($cRequestNo);
                        $this->load->view('search_global/closing_srnKrjAcc',$data); 
                        break;
                    case 'LOT PARKIR':
                        $data['getDetail']=$this->sGlobal_model->getDetailCloseSrnKrjPrk($cRequestNo);
                        $this->load->view('search_global/closing_srnKrjPrk',$data); 
                        break;
                }
                break;
            
            //ORI nya belum dikerjakan, sehingga belum ada panduan yang jelas    
            /*case 'publicRoom':
                $data['getDetail']=$this->sGlobal_model->getDetailPublicRoomGa($cRequestNo);
                foreach($data['getDetail'] as $rowIn){
                    $vcouriertype = $rowIn['DMR_COURIER_TYPE'];
                    $vRecieveDate = $rowIn['DMR_RECIEVE_DATE'];
                }
                if ($vcouriertype == "DOM" || $vcouriertype == "INT") {
                    $data['getKurir']=$this->sGlobal_model->getKurirPublicRoomGa($vcouriertype);
                }
                else{
                    $data['getKurir']=$this->sGlobal_model->getKurir2PublicRoomGa($vRecieveDate);
                }
                $this->load->view('search_global/approve_ga_publicRoom',$data); 
                break;
            case 'services':
                $data['getDetail']=$this->sGlobal_model->getDetailServicesGa($cRequestNo);
                $data['getDetail2']=$this->sGlobal_model->getDetail2ServicesGa($cRequestNo);
                //$data['getFloor2']=$this->sGlobal_model->getFloor2($cRequestNo);
                $this->load->view('search_global/approve_ga_services',$data); 
                break; 
                */           
        }
    }
    function closing_reqSave(){
        $arr['pReqClosing']         =  $_POST['pCtrlID'];
    	$arr['pReqClosingModul']    =  $_POST['pCType'];
    	$arr['pApproval']   		=  $_POST['pApproval'];
        $arr['pNikRequestBy']   	=  $_POST['pNikRequestBy'];
        $pNikRequestBy   	=  $_POST['pNikRequestBy'];
        $pReqClosing        =  $_POST['pCtrlID'];
        
        //var_dump($arr); exit;
        
        //stmt2 digunakan untuk sms, kerjakan nanti
        if(!empty($arr['pApproval'])){
            switch (strtoupper($arr['pReqClosingModul'])) {
    			case 'SURAT IJIN KERJA':
                    $msisdn = $this->sGlobal_model->getMsisdnSik($pReqClosing);
                    $arr['msisdn']   	=  $msisdn;
                    //var_dump($arr); exit;
                    $this->sGlobal_model->closeSrnKrjSikSave($arr);	
    				//$stmt1= "update fm_sik set sik_closing='$pApproval', sik_closing_date=sysdate where sik_id='$pReqClosing'";
    				//$stmt2= "select msisdn from hrs where id = (select SIK_UNTUK_NIK from fm_sik where sik_id='$pReqClosing')";
    				break;
    			case 'REQUEST GA':
                    $msisdn = $this->sGlobal_model->getMsisdnReq($pReqClosing);
                    $arr['msisdn']   	=  $msisdn;
                    //var_dump($arr); exit;
                    $this->sGlobal_model->closeSrnKrjReqSave($arr);
    				//$stmt1= "update fm_req_head set req_closing='$pApproval', req_closing_date=sysdate where req_id='$pReqClosing'";
    				//$stmt2= "select msisdn from hrs where id = (select REQ_UNTUK_NIK from fm_req_head where req_id='$pReqClosing')";
    				break;
    			case 'OVERTIME':
                    $msisdn = $this->sGlobal_model->getMsisdnOvt($pReqClosing);
                    $arr['msisdn']   	=  $msisdn;
                    //var_dump($arr); exit;
                    $this->sGlobal_model->closeSrnKrjOvtSave($arr);
    				//$stmt1= "update fm_so set so_closing='$pApproval', so_closing_date=sysdate where so_id='$pReqClosing'";
    				//$stmt2= "select msisdn from hrs where id = (select SO_UNTUK_NIK from fm_so where so_id='$pReqClosing')";
    				break;
    			case 'ACCESS CONTROL':
                    $msisdn = $this->sGlobal_model->getMsisdnAcc($pReqClosing);
                    $arr['msisdn']   	=  $msisdn;
                    //var_dump($arr); exit;
                    $this->sGlobal_model->closeSrnKrjAccSave($arr);	
    				//$stmt1= "update fm_access_control set ctrl_clossing='$pApproval', ctrl_clossing_date=sysdate where ctrl_id='$pReqClosing'";		   
    				//$stmt2= "select msisdn from hrs where id = (select CTRL_UNTUK_NIK from fm_access_control where ctrl_id='$pReqClosing')";
    				break;
    			case 'LOT PARKIR':
                    $msisdn = $this->sGlobal_model->getMsisdnPrk($pReqClosing);
                    $arr['msisdn']   	=  $msisdn;
                    //var_dump($arr); exit;
                    $this->sGlobal_model->closeSrnKrjPrkSave($arr);	
    				//$stmt1= "update fm_parkir_det set parkird_closing='$pApproval', parkird_closing_date=sysdate where parkird_id='$pReqClosing'";
    				//$stmt2= "select msisdn from hrs where id = (select PARKIRD_NIK from fm_parkir_det where parkird_id='$pReqClosing')";
    				break;
    			//case 'REPAIR ':
    			case 'REPAIR & MAINTENANCE':
                    $msisdn = $this->sGlobal_model->getMsisdnRm($pReqClosing);
                    $arr['msisdn']   	=  $msisdn;
                    //var_dump($arr); exit;
                    $this->sGlobal_model->closeSrnKrjRmSave($arr);	
    				//$stmt1= "update fm_rm set rm_closing='$pApproval', rm_closing_date=sysdate where rm_id='$pReqClosing'";
    				//$stmt2= "select msisdn from hrs where id = (select RM_UNTUK_NIK from fm_rm where rm_id='$pReqClosing')";
    				break;
    			//default:
    				//$stmt1= "select 'a' a from dual";	// dummy query :P
    		}
            
            //SCRIPT UNTUK SMS
            $msg = "FM : Order no : $pReqClosing telah dipenuhi oleh GA.";
            //send_sms($msisdn, $msg); //081219395711
            send_sms('081219395711', $msg.$msisdn);
        }
    }
    function edit_req(){
        $data['cRequestNo']=$this->input->post('cRequestNo');
        $data['cType']=$this->input->post('cType');
        $data['cTab']=$this->input->post('cTab');
        $cRequestNo=$data['cRequestNo'];
        $cType=$data['cType'];
        $cTab=$data['cTab'];
        //ambil session
        $CI =& get_instance();
        $data['sesName']=$CI->session->userdata('login')['name'];
        $data['sesJob']=$CI->session->userdata('login')['job'];
        $data['sesNik']=$CI->session->userdata('login')['nik'];
		$data['sesJobPosition']=$CI->session->userdata('login')['jobposition'];
        $data['sesOrg']=$CI->session->userdata('login')['org'];
        //var_dump($data); exit;
        
        //echo $cType;exit;
        switch($cTab){
            
            case 'saranaKerja':
                //$this->load->view('search_global/approve_ga',$data); 
                switch($cType){
                    case 'REQUEST GA':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditReq($cRequestNo);
                        $this->load->view('search_global/edit_srnKrjReq',$data);
                        break;
                    case 'OVERTIME':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditOvt($cRequestNo);
                        $data['getDetailVendor']=$this->sGlobal_model->getDetailEditOvtVendor($cRequestNo);
                        $data['getNik']=$this->sGlobal_model->getNik();
                        $data['getAtasanNik']=$this->sGlobal_model->getAtasanNik();
                        $data['getVendor']=$this->sGlobal_model->getVendor();
                        $data['getLantai']=$this->sGlobal_model->getLantai();
                        //$this->load->view("vheader");
                        $this->load->view('search_global/edit_srnKrjOvt',$data);
                        //$this->load->view('footer');
                        break;
                    case 'REPAIR & MAINTENANCE':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditRm($cRequestNo);
                        foreach($data['getDetail'] as $dta){
                            $typid=$dta['MST_TYPE_ID'];
                            $typval=$dta['RM_TYPE'];
                        }
                        $data['getType']=$this->sGlobal_model->getTypeRm();
                        $data['getCategory'] = $this->sGlobal_model->getCategoryFromType($typid);
                        //$data['getCategory']=$this->sGlobal_model->getCategoryRm($vType);
                        $this->load->view('search_global/edit_srnKrjRm',$data);
                        break;
                    case 'SURAT IJIN KERJA':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditSik($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetail2EditSik($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getFloorEditSik();
                        $this->load->view('search_global/edit_srnKrjSik',$data); break;
                    case 'ACCESS CONTROL':
                        //echo $sesName;
                        //echo $sesJob; 
                        //exit;
                        $data['getDetail']=$this->sGlobal_model->getDetailEditAcc($cRequestNo);
                        $vCtrlCard='';
                        foreach($data['getDetail'] as $dt){
                            $vCtrlCard=$dt['CARD'];
                            $vCtrlTelp=$dt['TELP'] ;
                        }
                        $data['getDetail2']=$this->sGlobal_model->getDetail2EditAcc();
                        $data['getTelp']=$this->sGlobal_model->getTelpEditAcc($vCtrlTelp,'SLI');
                        $data['getTelp2']=$this->sGlobal_model->getTelpEditAcc($vCtrlTelp,'SLJJ');
                        $data['getTelp3']=$this->sGlobal_model->getTelpEditAcc($vCtrlTelp,'LOKAL');
                        $data['getAtasan']=$this->sGlobal_model->getAtasan();
                        $data['getReference']=$this->sGlobal_model->getReference();
                        //getDetail3 ada di views yang langsung memanggil model
                        $this->load->view('search_global/edit_srnKrjAcc',$data); 
                        break;
                    case 'LOT PARKIR':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditPrk($cRequestNo);
                        $this->load->view('search_global/edit_srnKrjPrk',$data); 
                        break;
                }
                break;
            case 'publicRoom':
                switch($cType){
                    case 'MEETING ROOM': 
                        if($cRequestNo=='kosong'){ //arahkan ke public room->meeting room->add
                            ?>
                            <script>
                            top.location.href="<?php echo site_url("/public_room/meeting_room");?>";
                            </script>
                            <?php
                        }
                        else{
                            $data['getDetail']=$this->sGlobal_model->getDetailEditMeet($cRequestNo);
                            $data['getDetail2']=$this->sGlobal_model->getDetailEditMeet2($cRequestNo);
                            $this->load->view('search_global/edit_pubRomMeet',$data);
                        }
                        break;
                    case 'MAILLING ROOM':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditMail($cRequestNo); 
                        foreach($data['getDetail'] as $tmp){
                            $Courier=$tmp['DMR_COURIER_TYPE'];
                        }
                        if($Courier == 'DOM'){
            				$cond = "AND ISDOMESTIC ='Y'";
            				$data['get_Area'] = $this->sGlobal_model->getArea($cond);
            			}
            			else if($Courier == 'INT'){
            				$cond = "AND ISDOMESTIC ='N'";
            				$data['get_Area'] = $this->sGlobal_model->getArea($cond);
            			}
            			else{
            				$cond = "AND ISMESSENGER ='Y'";
            				$data['get_Area'] = $this->sGlobal_model->getArea($cond);
            			}
                        $this->load->view('search_global/edit_pubRomMail',$data);
                        break;    
                } 
                break;
            case 'services':
                switch($cType){
                    case 'PAGING INFO': //hanya 1 data tahun 2009, tidak terdapat menu edit
                        break;
                    case 'SARAN & KELUHAN': 
                        $data['getDetail']=$this->sGlobal_model->getDetailEditSarKel($cRequestNo);
                        $data['getType']=$this->sGlobal_model->getDetailEditSarKel2();
                        $this->load->view('search_global/edit_servSarKel',$data); 
                        break;
                    case 'ORDER EQUIPMENT':
                        $data['getDetail']=$this->sGlobal_model->getDetailEditOrder($cRequestNo); 
                        $data['getDetail2']=$this->sGlobal_model->getDetailEditOrder2($cRequestNo); 
                        $data['getDetailOther']=$this->sGlobal_model->getDetailEditOrder2Other($cRequestNo); 
                        $data['getDetailItem']=$this->sGlobal_model->getDetailEditOrderItem(); 
                        $this->load->view('search_global/edit_servOrder',$data); 
                        break;
                    case 'TRAFFIC': //no data 
                        break;         
                } 
                break;           
        }
    }
    function edit_reqSave(){
        $arr['pReqClosing']         =  $_POST['pCtrlID'];
    	$arr['pReqClosingModul']    =  $_POST['pCType'];
    	//$arr['pApproval']   		=  $_POST['pApproval'];
        //var_dump($arr); exit;
        
        //stmt2 digunakan untuk sms, kerjakan nanti
        //if(!empty($arr['pApproval'])){
            switch (strtoupper($arr['pReqClosingModul'])) {
    			case 'SURAT IJIN KERJA':
                    $this->edit_SikSave();
    				break;
    			case 'REQUEST GA':
                    $this->edit_gaSave();
    				break;
    			case 'OVERTIME':
                    $this->edit_OvtSave();
    				break;
                //PAGING INFO BELUM ADA DATANYA, BAHKAN DI PRODUCTION
    			case 'PAGING INFO':
    				break;
    			case 'ACCESS CONTROL':
                    $this->edit_AccSave();
    				break;
    			case 'LOT PARKIR':
                    $this->edit_PrkSave();
    				break;
    			//case 'REPAIR ':
    			case 'REPAIR & MAINTENANCE':
                    $this->edit_RmSave();
    				break;
                    
                case 'MAILLING ROOM':
                    $this->edit_mailSave();
    				break;
                case 'MEETING ROOM':
                    $this->edit_meetSave();
    				break;
                    
                case 'SARAN & KELUHAN':
                    $this->edit_sarKelSave();
    				break;        
                case 'ORDER EQUIPMENT':
                    $this->edit_orderSave();
    				break;
    			//default:
    				//$stmt1= "select 'a' a from dual";	// dummy query :P
    		//}
            
            //SCRIPT UNTUK SMS
            /*$DB2->parse($stmt2);
    		$DB2->execute();
    		if($a=$DB2->nextrow()) {
    			$msisdn = $a['MSISDN'];
    			$msg = "FM : Order no : $pReqClosing telah dipenuhi oleh GA.";
    			send_sms($msisdn, $msg);
    		}
    
    		$DB1->parse($stmt1);
    		$DB1->execute();*/
        }
    }
    
    
    //ACCESS CONTROL EDIT SAVE===========================START================================================
    public function edit_AccSave(){
        $arr['pCtrlID']			    =  $_POST['pCtrlID'];
    	$arr['pCtrlCheck1'] 		=  $_POST['pCtrlCheck1'];
    	$arr['pCtrlCheck2'] 		=  $_POST['pCtrlCheck2'];
    	
    	$arr['pCtrlLokal'] 		=  $_POST['pCtrlLokal'];
    	$arr['pCtrlSljj'] 			=  $_POST['pCtrlSljj'];
    	$arr['pCtrlSli'] 			=  $_POST['pCtrlSli'];
    	
    	$arr['pCtrlCardFloor'] 	=  $_POST['pCardFloor'];
    	$arr['pCtrlUserType'] 		=  $_POST['pCtrlUserType'];
    	
    	$arr['pCtrlUserName'] 		=  $_POST['pNameFor'];
    	$arr['pCtrlVendor']		=  $_POST['pDepartemenFor'];
    	$arr['pCtrlDesc'] 			=  $_POST['pCtrlDesc'];
    	$arr['pAtasanNik']			=  $_POST['pAtasanNik'];
    	
    	$arr['pCtrlSik']			=  $_POST['pCtrlSik'];
    	$arr['pDate1']				=  $_POST['pDate1'];
    	$arr['pDate2']				=  $_POST['pDate2'];
    	$arr['pNikFor']			=  $_POST['pNikFor'];
    	$arr['pFloor']				=  $_POST['pFloor'];
        $arr['pPhoneFisik']		=  $_POST['pPhoneFisik'];
    	$arr['pCardFisik']			=  $_POST['pCardFisik'];
        
        var_dump($arr); 
        //var_dump($arr['pCtrlCheck1']);  var_dump($arr['pCtrlCheck2']); var_dump($arr['pCtrlCardFloor']); var_dump($arr['pFloor']);
        $pCtrlID			=  $arr['pCtrlID'];
    	$pCtrlCheck1 		=  $arr['pCtrlCheck1'];
    	$pCtrlCheck2 		=  $arr['pCtrlCheck2'];
    	
    	$pCtrlLokal 		=  $arr['pCtrlLokal'];
    	$pCtrlSljj 			=  $arr['pCtrlSljj'];
    	$pCtrlSli 			=  $arr['pCtrlSli'];
    	
    	$pCtrlCardFloor 	=  $arr['pCtrlCardFloor'];
    	$pCtrlUserType 		=  $arr['pCtrlUserType'];
    	
    	$pCtrlUserName 		=  $arr['pNameFor'];
    	$pCtrlVendor		=  $arr['pDepartemenFor'];
    	$pCtrlDesc 			=  $arr['pCtrlDesc'];
    	$pAtasanNik			=  $arr['pAtasanNik'];
    	
    	$pCtrlSik			=  $arr['pCtrlSik'];
    	$pDate1				=  $arr['pDate1'];
    	$pDate2				=  $arr['pDate2'];
    	$pNikFor			=  $arr['pNikFor'];
    	$pFloor				=  $arr['pFloor'];
        $pPhoneFisik		=  $arr['pPhoneFisik'];
    	$pCardFisik			=  $arr['pCardFisik'];
    	
    	
        $arr['vDate1'] = $pDate1;
    	$arr['vDate2'] = $pDate2;
    	$vDate1 = $arr['vDate1'];
    	$vDate2 = $arr['vDate2'];
    	
        
        //UPDATE FM_ACCESS_CONTROL
    	$this->sGlobal_model->accUpdate1($arr);	
    	
        //JIKA ACCESS CONTROL CENTANG
    	if(!empty($pCtrlCheck1) && $pCtrlCheck1 == 'Y') {
    	   $accSelect1=$this->sGlobal_model->AccSelect1();
            foreach($accSelect1 as $a){
                $cCtrlCardIdOld = $a["CTRL_CARD_ID_OLD"];	
    			$cRomawi    = $a["ROMAWI"];	
    			$cCtrlCardIdNew = $cCtrlCardIdOld +1;
            }
    		$accSelect2=$this->sGlobal_model->accSelect2($cCtrlCardIdNew,$cRomawi);
            foreach($accSelect2 as $a){
                $cCtrCardlId = $a["CTRL_CARD_ID"];	
            }	
    		
            $accSelect3=$this->sGlobal_model->accSelect3($arr);
            foreach($accSelect3 as $row){
                $pCardId = $row['CTRL_CARD_ID'];
            }
            var_dump($pCardId); //exit();
            //JIKA CARD ID KOSONG
    		if(empty($pCardId)) {
    		    //INSERT KE FM_CONTROL_CARD  
                $this->sGlobal_model->accInsert1($arr,$cCtrCardlId);
    			//var_dump($cCtrCardlId); 
                $accSelect4=$this->sGlobal_model->accSelect4();
                foreach($accSelect4 as $row){
                    $cnt = $row['CNT_ROW'];
                }
    			//JIKA ACCESS CONTROL DICENTANG
    			if(!empty($pCtrlCheck1) && $pCtrlCheck1 == 'Y') {
    				for($x=0; $x < $cnt; $x++) {
    				    //JIKA FLOOR NYA DICENTANG
    					if(!empty($pCtrlCardFloor[$x]) && $pCtrlCardFloor[$x] == 'Y') {
    						$y = $x+1 ;
                            //INSERT KE CONTROL_CARD_FLOOR
                            $this->sGlobal_model->accInsert2($pFloor[$x],$cCtrCardlId);
    						$y = 0;
    					}
                        else {
                            //DELETE DI CONTROL_CARD_FLOOR
                            $this->sGlobal_model->accDelete1($pFloor[$x],$pCardId);
    					}
    				}
    			}
    		}
            //JIKA CARD ID ADA ISINYA
            else {
                //echo "SAMPE SINi"; 
    		    $accSelect5=$this->sGlobal_model->accSelect5();
                foreach($accSelect5 as $row){
                    $cnt = $row['CNT_ROW'];
                }  
    			//echo $cnt; exit;
                //JIKA ACCESS CONTROL DICENTANG
    			if(!empty($pCtrlCheck1) && $pCtrlCheck1 == 'Y') {
    				for($x=0; $x < $cnt; $x++) {
    				    //JIKA FLOOR DICENTANG
    					if(!empty($pCtrlCardFloor[$x]) && $pCtrlCardFloor[$x] == 'Y') {
    						$y = $x+1 ;
                            //INSERT KE CONTROL CARD FLOOR 
                            //echo $pCtrlCardFloor[$x]."<br>";
                            $this->sGlobal_model->accInsert3($pFloor[$x],$pCardId);
    						$y = 0;
    					}
                        //JIKA FLOOR UNCENTANG
                        else {
    					    $this->sGlobal_model->accDelete2($pFloor[$x],$pCardId);
    					}
    				}
    			}
                //echo $x;exit;
    		}
    	}
        //JIKA ACCESS CONTROL UNCENTANG
        else {
    	    $this->sGlobal_model->accDelete3($arr);
            $this->sGlobal_model->accDelete4($arr); 
    	}
    	
        
        
        
        //JIKA LINE TELP TERCENTANG
    	if(!empty($pCtrlCheck2) && $pCtrlCheck2 == 'Y') {
    	    $accSelect6=$this->sGlobal_model->accSelect6();
            foreach($accSelect6 as $a){
                $cCtrlTelpIdOld = $a["CTRL_TELP_ID_OLD"];	
    			$cRomawi    = $a["ROMAWI"];	
    			$cCtrlTelpIdNew = $cCtrlTelpIdOld +1;
            }
    		$accSelect7=$this->sGlobal_model->accSelect7($cCtrlTelpIdNew,$cRomawi);
            foreach($accSelect7 as $a){
                $cCtrTelplId = $a["CTRL_TELP_ID"];	
            }
            $accSelect8=$this->sGlobal_model->accSelect8($pCtrlID);
            foreach($accSelect8 as $row){
                $pTelpId = $row['CTRL_TELP_ID'];
            }
            //echo $pTelpId;
            //JIKA TELP ID KOSONG
    		if(empty($pTelpId)) {
    		    //INSERT KE FM_CONTROL_TELP
    		    $this->sGlobal_model->accInsert4($arr,$cCtrTelplId);
    			if(!empty($pCtrlLokal) && $pCtrlLokal == "Y") {
		            //INSERT CONTROL_TELP_EXT
    			    $this->sGlobal_model->accInsert5($cCtrTelplId);
    			}
    			
    			if(!empty($pCtrlSljj) && $pCtrlSljj == "Y") {
    			     //INSERT CONTROL_TELP_EXT
    			    $this->sGlobal_model->accInsert6($cCtrTelplId); 
    			}
    			
    			if(!empty($pCtrlSli) && $pCtrlSli == "Y") {
    			     //INSERT CONTROL_TELP_EXT
    			     $this->sGlobal_model->accInsert7($cCtrTelplId);
    			}
    		}
            //JIKA TELP ID ADA ISINYA
            else {
    			if(!empty($pCtrlLokal) && $pCtrlLokal == "Y") {
		            //INSERT CONTROL_TELP_EXT
    			    $this->sGlobal_model->accInsert8($pTelpId); 
                    //echo $pTelpId." SAMPE INSERT"; //exit;
    			}
                else {
		            //DELETE CONTROL_TELP_EXT
                    $this->sGlobal_model->accDelete5($pTelpId); 
                    //echo $pTelpId." SAMPE DELETE"; //exit;
    			}
    			
    			if(!empty($pCtrlSljj) && $pCtrlSljj == "Y") {
    			     //INSERT CONTROL_TELP_EXT
                     $this->sGlobal_model->accInsert9($pTelpId);
    			}
                else {
    			     //DELETE CONTROL_TELP_EXT
                     $this->sGlobal_model->accDelete6($pTelpId);
    			}
    			
    			if(!empty($pCtrlSli) && $pCtrlSli == "Y") {
    			     //INSERT CONTROL_TELP_EXT
    			     $this->sGlobal_model->accInsert10($pTelpId);
    			}else {
    			     //DELETE CONTROL_TELP_EXT
                     $this->sGlobal_model->accDelete7($pTelpId);
    			}
                
    		}
    	}
        //JIKA LINE TELP UNCENTANG
        else {
    	    //DELETE CONTROL_TELP_EXT  
            $this->sGlobal_model->accDelete8($pCtrlID);
            //DELETE FM_CONTROL_TELP 
            $this->sGlobal_model->accDelete9($pCtrlID);
    	}
        
        
    }
    //ACCESS CONTROL EDIT SAVE===========================END================================================
    
    //OVERTIME EDIT SAVE===========================START================================================
    public function edit_OvtSave(){
            $arr['BtnSubmit']    	    =  $_POST['BtnSubmit'];
            $arr['pSoId']    			=  $_POST['pSoId'];
            $arr['pCType']             =  $_POST['pCType'];
            $arr['pNik']    			=  $_POST['pNik'];
            $arr['pSdate']    			=  $_POST['pSdate'];
            $arr['pEdate']    			=  $_POST['pEdate'];
            $arr['pShour']    			=  $_POST['pShour'];
            $arr['pEhour']    			=  $_POST['pEhour'];
            $arr['pSminute']   		   =  $_POST['pSminute'];
            $arr['pEminute']   		   =  $_POST['pEminute'];
            $arr['pAc']    			  =  $_POST['pAc'];
            $arr['pLift']    			=  $_POST['pLift'];
            $arr['pLighting']  		   =  $_POST['pLighting'];
            $arr['pOther']  			=  $_POST['pOther'];
            $arr['pOtherDescription']  =  $_POST['pOtherDescription'];
            $arr['pDescription']  		=  $_POST['pDescription'];
            $arr['pTotalDetail']  		=  $_POST['pTotalDetail'];
            $arr['pAtasanNik']  		=  $_POST['pAtasanNik'];
            $arr['pAtasanNama']  		=  $_POST['pAtasanNama'];
            $arr['pNikFor']    		=  $_POST['pNikFor'];
            
            $arr['pReqId']    			=  $_POST['pReqId'];
            $arr['pReqDetId']    		=  $_POST['pReqDetId'];
            
            //UNTUK PILIHAN TABEL BAWAH
            $arr['pSodId']              = $_POST['pSodId'];
            $arr['pSodName']            = $_POST['pSodName'];
            $arr['pSodFloor']           = $_POST['pSodFloor'];
            $arr['pSodLocation']        = $_POST['pSodLocation'];
            $arr['pSodVendorId']        = $_POST['pSodVendorId'];
            $arr['pSodVendorName']      = $_POST['pSodVendorName'];
            
            //var_dump($arr); exit;
            $BtnSubmit    		= $arr['BtnSubmit'];
            $pSoId    			= $arr['pSoId'];
            $pCType             = $arr['pCType'];
            $pNik    			= $arr['pNik'];
            $pSdate    			= $arr['pSdate'];
            $pEdate    			= $arr['pEdate'];
            $pShour    			= $arr['pShour'];
            $pEhour    			= $arr['pEhour'];
            $pSminute   		= $arr['pSminute'];
            $pEminute   		= $arr['pEminute'];
            $pAc    			= $arr['pAc'];
            $pLift    			= $arr['pLift'];
            $pLighting  		= $arr['pLighting'];
            $pOther  			= $arr['pOther'];
            $pOtherDescription  = $arr['pOtherDescription'];
            $pDescription  		= $arr['pDescription'];
            $pTotalDetail  		= $arr['pTotalDetail'];
            $pAtasanNik  		= $arr['pAtasanNik'];
            $pAtasanNama  		= $arr['pAtasanNama'];
            $pNikFor    		= $arr['pNikFor'];
            
            $pReqId    			= $arr['pReqId'];
            $pReqDetId    		= $arr['pReqDetId'];
            
            //UNTUK PILIHAN TABEL BAWAH
            $pSodId             = $arr['pSodId'];
            $pSodName           = $arr['pSodName'];
            $pSodFloor          = $arr['pSodFloor'];
            $pSodLocation       = $arr['pSodLocation'];
            $pSodVendorId       = $arr['pSodVendorId'];
            $pSodVendorName     = $arr['pSodVendorName'];
            //var_dump($arr); exit;
            
    //JIKA REQUEST_NO ADA ISINYA DAN START DATE ADA ISINYA (MENU EDIT)
    if(!empty($pSoId) && !empty($pSdate)){
    //UPDATE FM_SO
        $this->sGlobal_model->ovtUpdate1($arr);
        //if ($_SERVER['REMOTE_ADDR']=='10.2.148.114') echo $stmt1, "<br>\n";
        $cSoId = $pSoId;       
     }
                //SELAIN ITU MENU ADD
     else{
          $ovtSelect1=$this->sGlobal_model->ovtSelect1();   
          
          foreach($ovtSelect1 as $a){
            $cSoIdOld = $a["SO_ID_OLD"];
            $cRomawi  = $a["ROMAWI"];
            $cSoIdNew = $cSoIdOld +1;
          }
          
          $ovtSelect2=$this->sGlobal_model->ovtSelect2($cSoIdNew);       
          foreach($ovtSelect2 as $a){
            $cSoId = $a["SO_ID"];
          }
              
          
          //INSERT FM_SO
          $ovtInsert1=$this->sGlobal_model->ovtInsert1($arr,$cSoId);  
                    
          //UPDATE FM_REQ_DET
          $ovtUpdate2=$this->sGlobal_model->ovtUpdate2($pReqId,$pReqDetId);
                
          //if ($_SERVER['REMOTE_ADDR']=='10.2.148.114') echo $stmt1, "<br>\n";
          //if ($_SERVER['REMOTE_ADDR']=='10.2.148.114') echo $stmt2, "<br>\n";
                
                
           }
                //echo "<hr>$stmt1<hr>";
                //echo "<hr>$stmt2<hr>";
                
                
                
                
            //$pTotalDetail=$pTotalDetail+1;
            for($x=0;$x<$pTotalDetail;$x++){
                    //JIKA REQUEST_NO KOSONG ARTINYA MERUPAKAN MENU ADD / BUKAN MENU EDIT
                	if(empty($pSoId)){
                		if(!empty($pSodName[$x]) && empty($pSodId[$x])){
                		    //INSERT FM_SO_DET   
                            $ovtInsert2=$this->sGlobal_model->ovtInsert2($pSodName[$x],$pSodFloor[$x],$pSodLocation[$x],$pSodVendorId[$x],$pSodVendorName[$x],$cSoId);
                		
                			$msg = "FM : Order No $cSoId telah berhasil, untuk Proses selanjutnya menunggu Approval dari atasan anda $pAtasanNama.";
                			$msgatasan = "FM : Order No $cSoId membutuhkan approval anda.";
                            
                            /* 
                            //KIRIM SMS
                			$msisdn = dbora_getgamsisdn($pNikFor);
                			send_sms($msisdn, $msg);
                	
                			$msisdnatasan = dbora_getgamsisdn($pAtasanNik);
                			send_sms($msisdnatasan, $msgatasan);
                            */
                		}
                	}
                    //JIKA REQUEST_NO ADA ARTINYA MERUPAKAN MENU EDIT
                    else{
                        //JIKA ID NYA KOSONG & NAMA NYA ADA    
                		if(empty($pSodId[$x]) && !empty($pSodName[$x])){
                		    //INSERT FM_SO_DET    
                            $ovtInsert2=$this->sGlobal_model->ovtInsert2($pSodName[$x],$pSodFloor[$x],$pSodLocation[$x],$pSodVendorId[$x],$pSodVendorName[$x],$pSoId);
                		}
                        //JIKA ID NYA ADA & NAMA NYA ADA
                        else if(!empty($pSodId[$x]) && !empty($pSodName[$x])){
                            //UPDATE FM_SO_DET  
                            $ovtUpdate3=$this->sGlobal_model->ovtUpdate3($pSodName[$x],$pSodFloor[$x],$pSodLocation[$x],$pSodVendorId[$x],$pSodVendorName[$x],$pSodId[$x]);
                		}
                	}
                
                	//if ($_SERVER['REMOTE_ADDR']=='10.2.148.114') echo $qry4, "<br>\n";
                }
        
        
    }
    
    //OVERTIME EDIT SAVE===========================END================================================
    
    //SIK EDIT SAVE===========================START===================================================
    public function edit_SikSave(){
        $arr['pCType']    			=  $_POST['pCType'];
        $arr['pSikId']    			=  $_POST['pSikId'];
    	//$BtnSubmit			=  $_POST['submit'];
    	$arr['pNik']    			=  $_POST['pNik'];
    	//$pTypeId    		=  $_POST['pTypeId'];
    	//$pFloorId    		=  $_POST['pFloorId'];
    	$arr['pVendorId']    		=  $_POST['pVendorId'];
    	$arr['pVendorName']    	=  $_POST['pVendorName'];
    	$arr['pPic']    			=  $_POST['pPic'];
    	$arr['pJabatan']    		=  $_POST['pJabatan'];
    	$arr['pAtasanNik']    		=  $_POST['pAtasanNik'];
    	$arr['pAtasanNama']    	=  $_POST['pAtasanNama'];
    	$arr['pNikFor']    		=  $_POST['pNikFor'];
    	$arr['pSdate']    			=  $_POST['pSdate'];
    	$arr['pEdate']    			=  $_POST['pEdate'];
    	$arr['pShour']    			=  $_POST['pShour'];
    	$arr['pEhour']    			=  $_POST['pEhour'];
    	$arr['pSminute']    		=  $_POST['pSminute'];
    	$arr['pEminute']    		=  $_POST['pEminute'];
        $arr['pJumlahI']    		=  $_POST['pJumlahI'];
        
        $arr['pSikjId']          = $_POST['pSikIdBawah'];
        $arr['pSikjName']        = $_POST['pSikName'];
        $arr['pSikjDesc']   = $_POST['pSikPekerjaan'];
        $arr['pSikjFloor']      = $_POST['pSikLantai'];
        $arr['pSikjLocation']    = $_POST['pSikLocation'];
        $arr['pSikjAccess']      = $_POST['pSikAccess'];
        $arr['pSikjBarang']  = $_POST['pSikNamaBarang'];
        $arr['pSikjSn']      = $_POST['pSikSerial'];
        
        $pCType    			=  $arr['pCType'];
        $pSikId    			=  $arr['pSikId'];
    	$pNik    			=  $arr['pNik'];
    	$pVendorId    		=  $arr['pVendorId'];
    	$pVendorName    	=  $arr['pVendorName'];
    	$pPic    			=  $arr['pPic'];
    	$pJabatan    		=  $arr['pJabatan'];
    	$pAtasanNik    		=  $arr['pAtasanNik'];
    	$pAtasanNama    	=  $arr['pAtasanNama'];
    	$pNikFor    		=  $arr['pNikFor'];
    	$pSdate    			=  $arr['pSdate'];
    	$pEdate    			=  $arr['pEdate'];
    	$pShour    			=  $arr['pShour'];
    	$pEhour    			=  $arr['pEhour'];
    	$pSminute    		=  $arr['pSminute'];
    	$pEminute    		=  $arr['pEminute'];
        $pJumlahI    		=  $arr['pJumlahI'];
        
        $pSikjId          = $arr['pSikjId'];
        $pSikjName        = $arr['pSikjName'];
        $pSikjDesc   = $arr['pSikjDesc'];
        $pSikjFloor     = $arr['pSikjFloor'];
        $pSikjLocation    = $arr['pSikjLocation'];
        $pSikjAccess      = $arr['pSikjAccess'];
        $pSikjBarang  = $arr['pSikjBarang'];
        $pSikjSn      = $arr['pSikjSn'];
        
        //var_dump($arr); exit;
    	
    	//$pTotalDetailName  	=  $_POST['pTotalDetailName'];
    	//$pTotalDetailJob  	=  $_POST['pTotalDetailJob'];
    	//$pTotalDetailBrg  	=  $_POST['pTotalDetailBrg'];
    	
    	$pReqId    		=  $_POST['pReqId'];
    	$pReqDetId    	=  $_POST['pReqDetId'];
        
    	//$msg 			=  "";
        //$vAtasanName	= dbora_getname($pAtasanNik);
    	
        echo $pSikId."SIKID";
    	if(!empty($pSikId) && !empty($pVendorId)){	
    	    //UPDATE FM_SIK
            $sikUpdate1=$this->sGlobal_model->sikUpdate1($arr);
    	}
        else{
            $sikSelect1=$this->sGlobal_model->sikSelect1();
    		foreach($sikSelect1 as $a){
    			$cSikIdOld = $a["SIK_ID_OLD"];	
    			$cRomawi  = $a["ROMAWI"];	
    			$cSikIdNew = $cSikIdOld +1;
    		}
    		//SELECT FM_SIK
    		$sikSelect2=$this->sGlobal_model->sikSelect2($cSikIdNew,$cRomawi);	
    		foreach($sikSelect2 as $a){
    			$cSikId = $a["SIK_ID"];	
    		}
    		
    		//INSERT FM_SIK
            $sikInsert1=$this->sGlobal_model->sikInsert1($arr,$cSikId);
            //UPDATE FM_REQ_DET
            $sikUpdate2=$this->sGlobal_model->sikUpdate2($pReqId,$pReqDetId);
            /*
            // FOR SMS	
                  $msg = "FM : Order No $cSikId telah berhasil, untuk Proses selanjutnya menunggu Approval dari atasan anda $vAtasanName.";			
    		      $msgatasan = "FM : Order No $cSikId membutuhkan approval anda.";
    		
    		// Sms to User
    		$msisdn = dbora_getgamsisdn($pNikFor);
    		send_sms($msisdn, $msg);
    		//End Sms User
    	
    		// Sms to Atasan
    		$msisdnatasan = dbora_getgamsisdn($pAtasanNik);
    		send_sms($msisdnatasan, $msgatasan);
    		//End Sms Atasan
    			
    		//End Sms	
            */    
    			
    	}
    	//echo "$stmt1<br><br>";
    	
    	echo $pJumlahI."JUMLAH I";
    	for($x=0;$x<$pJumlahI;$x++){
    	   /*
    		$pSikjId		=  $_POST['pSikjId'];	
    		$pSikjName		=  $_POST['pSikjName'];	
    		$pSikjDesc		=  $_POST['pSikjDesc'];	
    		$pSikjFloor		=  $_POST['pSikjFloor'];	
    		$pSikjLocation	=  $_POST['pSikjLocation'];	
    		$pSikjAccess	=  $_POST['pSikjAccess'];	
    		$pSikjBarang	=  $_POST['pSikjBarang'];	
    		$pSikjSn		=  $_POST['pSikjSn'];	
    		*/
    		if(empty($pSikId)){
    			if(!empty($pSikjName[$x])){
    			    //INSERT FM_SIK_JOB 
                    $sikInsert2=$this->sGlobal_model->sikInsert2($pSikjName[$x],$pSikjLocation[$x],$pSikjFloor[$x],$pSikjSn[$x],$pSikjAccess[$x],$pSikjDesc[$x],$pSikjBarang[$x],$cSikId);
    			}			
    		}
            else{
    			if(empty($pSikjId[$x]) && !empty($pSikjName[$x])){
    			    //INSERT FM_SIK_JOB
                    $sikInsert3=$this->sGlobal_model->sikInsert3($pSikjName[$x],$pSikjLocation[$x],$pSikjFloor[$x],$pSikjSn[$x],$pSikjAccess[$x],$pSikjDesc[$x],$pSikjBarang[$x],$pSikId);
    			}
                else if(!empty($pSikjId[$x]) && !empty($pSikjName[$x])){
                    //UPDATE FM_SIK_JOB
                    $sikUpdate3=$this->sGlobal_model->sikUpdate3($pSikjName[$x],$pSikjLocation[$x],$pSikjFloor[$x],$pSikjSn[$x],$pSikjAccess[$x],$pSikjDesc[$x],$pSikjBarang[$x],$pSikjId[$x]);
    			}
    		}
    	}
    	
    	if(empty($pSikId)){
    	   $xSikId = $cSikId;
    	}
        else{
    	   $xSikId = $pSikId;
        }	
    }
    
    function saveAtasSik(){
        $arr['pCType']    			=  $_POST['pCType'];
        $arr['pSikId']    			=  $_POST['pSikId'];
    	$arr['pNik']    			=  $_POST['pNik'];
    	$arr['pVendorId']    		=  $_POST['pVendorId'];
    	$arr['pVendorName']    	=  $_POST['pVendorName'];
    	$arr['pPic']    			=  $_POST['pPic'];
    	$arr['pJabatan']    		=  $_POST['pJabatan'];
    	$arr['pAtasanNik']    		=  $_POST['pAtasanNik'];
    	$arr['pAtasanNama']    	=  $_POST['pAtasanNama'];
    	$arr['pNikFor']    		=  $_POST['pNikFor'];
    	$arr['pSdate']    			=  $_POST['pSdate'];
    	$arr['pEdate']    			=  $_POST['pEdate'];
    	$arr['pShour']    			=  $_POST['pShour'];
    	$arr['pEhour']    			=  $_POST['pEhour'];
    	$arr['pSminute']    		=  $_POST['pSminute'];
    	$arr['pEminute']    		=  $_POST['pEminute'];
        $arr['pJumlahI']    		=  $_POST['pJumlahI'];
        
        $pCType    			=  $arr['pCType'];
        $pSikId    			=  $arr['pSikId'];
    	$pNik    			=  $arr['pNik'];
    	$pVendorId    		=  $arr['pVendorId'];
    	$pVendorName    	=  $arr['pVendorName'];
    	$pPic    			=  $arr['pPic'];
    	$pJabatan    		=  $arr['pJabatan'];
    	$pAtasanNik    		=  $arr['pAtasanNik'];
    	$pAtasanNama    	=  $arr['pAtasanNama'];
    	$pNikFor    		=  $arr['pNikFor'];
    	$pSdate    			=  $arr['pSdate'];
    	$pEdate    			=  $arr['pEdate'];
    	$pShour    			=  $arr['pShour'];
    	$pEhour    			=  $arr['pEhour'];
    	$pSminute    		=  $arr['pSminute'];
    	$pEminute    		=  $arr['pEminute'];
        $pJumlahI    		=  $arr['pJumlahI'];
        
        //UPDATE FM_SIK
        $sikUpdate1=$this->sGlobal_model->sikUpdate1($arr);
    }
    function addBawahForm()
	{
        $data['cType'] = trim($this->input->post('cType'));
        $data['cRequestNo'] = trim($this->input->post('cRequestNo'));
        $cType=$data['cType'];
        $cRequestNo=$data['cRequestNo'];
        switch($cType){
            case 'SURAT IJIN KERJA': 
                $data['getFloor']=$this->sGlobal_model->getFloorEditSik();
                $this->load->view('search_global/addBawahFormSik',$data);
                break;
        }
        
	}
    function editBawahForm()
	{
        $data['cType'] = trim($this->input->post('cType'));
        $data['cRequestNo'] = trim($this->input->post('cRequestNo'));
        $cType=$data['cType'];
        $cRequestNo=$data['cRequestNo'];
        switch($cType){
            case 'SURAT IJIN KERJA': 
                $data['cSikjId'] = trim($this->input->post('cSikjId'));
                $cSikjId=$data['cSikjId'];
                $data['getDetailBawah']=$this->sGlobal_model->getDetailBawahSik($cRequestNo,$cSikjId);
                $data['getFloor']=$this->sGlobal_model->getFloorEditSik();
                $this->load->view('search_global/editBawahFormSik',$data);
                break;
            case 'OVERTIME':
                $data['cSodId'] = trim($this->input->post('cSodId'));
                $cSodId=$data['cSodId'];
                $data['getDetailBawah']=$this->sGlobal_model->getDetailBawahOvt($cRequestNo,$cSodId);
                $data['getDetailVendor']=$this->sGlobal_model->getDetailEditOvtVendor($cRequestNo);
                //$data['getVendor']=$this->sGlobal_model->getVendor();
                $data['getLantai']=$this->sGlobal_model->getLantai();
                $this->load->view('search_global/editBawahFormOvt',$data);
                break;
        }
        
	}
    function deleteBawahForm()
	{
        $data['cType'] = trim($this->input->post('cType'));
        $data['cRequestNo'] = trim($this->input->post('cRequestNo'));
        $data['cSikjId'] = trim($this->input->post('cSikjId'));
        $cType=$data['cType'];
        $cSikjId=$data['cSikjId'];
        $cRequestNo=$data['cRequestNo'];
        switch($cType){
            case 'SURAT IJIN KERJA': 
                $data['getDetailBawah']=$this->sGlobal_model->getDetailBawahSik($cRequestNo,$cSikjId);
                $data['getFloor']=$this->sGlobal_model->getFloorEditSik();
                $this->load->view('search_global/deleteBawahFormSik',$data);
                break;
        }
        
	}
    //SIK EDIT SAVE===========================END=====================================================
    
    //PARKIR EDIT SAVE===========================START===================================================
    public function edit_PrkSave(){
        $pStatus = $_POST['pStatus'];
        $pReqId = $_POST['pReqId'];
        $pReqDetId = $_POST['pReqDetId'];
        $pParkirdId = $_POST['pCtrlID'];
        $pCType=$_POST['pCType'];
        $pFile = $_FILES['file']['tmp_name'];
        //$pFile = $_POST['file'];
        /*
        $fdest = "upload/a.jpg";
        move_uploaded_file($_FILES["file"]["tmp_name"], $fdest);  
        ?>
        <script>
            top.location.href="<?php echo site_url("/search_global/search_global");?>";
        </script>
        <?php  
        //echo $pFile; exit;
        */
        
        $msg = "";
        $pNik = $_POST['pNik'];
        $pNikFor = $_POST['r_id']; //
        $pStatusFor = $_POST['pStatusFor'];
        $pAktif = $_POST['CarRadio'];
            $pParkirType1 = "MOBIL";
            $pStnk1 = $_POST['Certificate1'];
            $pPlat1 = $_POST['License1'];
            $pParkirType2 = "MOBIL";
            $pStnk2 = $_POST['Certificate2'];
            $pPlat2 = $_POST['License2'];
            $pParkirType3 = "MOBIL";
            $pStnk3 = $_POST['Certificate3'];
            $pPlat3 = $_POST['License3'];
            $pParkirType4 = "MOTOR";
            $pStnk4 = $_POST['Certificate4'];
            $pPlat4 = $_POST['License4'];
        $pFile = $_POST['file'];
            $tmpname = $_FILES['file']['tmp_name'];
            $filename = $_FILES['file']['name'];
            $filesize = $_FILES['file']['size'];
            $filetype = $_FILES['file']['type'];
        $pAtasanNik = $_POST['r_mgrid'];
        $pAtasanNama = $_POST['r_mgr'];
        $pDescription = str_replace("'", "x", $_POST['pDescription']);
        
        //var_dump($tmpname); exit;
        $arr['pParkirdId'] = $_POST['pCtrlID'];
        $arr['pCType']=$_POST['pCType'];
        $arr['pStatus'] = $_POST['pStatus'];
        $arr['pReqId'] = $_POST['pReqId'];
        $arr['pReqDetId'] = $_POST['pReqDetId'];
        
        $arr['msg'] = "";
        $arr['pNik'] = $_POST['pNik'];
        $arr['pNikFor'] = $_POST['r_id']; //
        $arr['pStatusFor'] = $_POST['pStatusFor'];
        $arr['pAktif'] = $_POST['CarRadio'];
            $arr['pParkirType1'] = "MOBIL";
            $arr['pStnk1'] = $_POST['Certificate1'];
            $arr['pPlat1'] = $_POST['License1'];
            $arr['pParkirType2'] = "MOBIL";
            $arr['pStnk2'] = $_POST['Certificate2'];
            $arr['pPlat2'] = $_POST['License2'];
            $arr['pParkirType3'] = "MOBIL";
            $arr['pStnk3'] = $_POST['Certificate3'];
            $arr['pPlat3'] = $_POST['License3'];
            $arr['pParkirType4'] = "MOTOR";
            $arr['pStnk4'] = $_POST['Certificate4'];
            $arr['pPlat4'] = $_POST['License4'];
        $arr['pFile'] = $_POST['file'];
            $arr['tmpname'] = $_FILES['file']['tmp_name'];
            $arr['filename'] = $_FILES['file']['name'];
            $arr['filesize'] = $_FILES['file']['size'];
            $arr['filetype'] = $_FILES['file']['type'];
        $arr['pAtasanNik'] = $_POST['r_mgrid'];
        $arr['pAtasanNama'] = $_POST['r_mgr'];
        $arr['pDescription'] = str_replace("'", "x", $_POST['pDescription']);
        //$vAtasanName = dbora_getname($pAtasanNik);
        //$pStatus = $_POST['pStatus'];
        //$pReqId = $_POST['pReqId'];
        //$pReqDetId = $_POST['pReqDetId'];
        
        
        if ($pAktif == 1) { //JIKA PILIHAN ADALAH MOBIL 1
            $pParkirType = $pParkirType1;
            $pPlat = $pPlat1;
            $pStnk = $pStnk1;
            $pFlag1 = 'Y';
            $arr['pParkirType'] = $pParkirType1;
            $arr['pPlat'] = $pPlat1;
            $arr['pStnk'] = $pStnk1;
            $arr['pFlag1'] = 'Y';
        } 
        else if ($pAktif == 2) {    ////JIKA PILIHAN ADALAH MOBIL 2
            $pParkirType = $pParkirType2;
            $pPlat = $pPlat2;
            $pStnk = $pStnk2;
            $pFlag2 = 'Y';
            $arr['pParkirType'] = $pParkirType2;
            $arr['pPlat'] = $pPlat2;
            $arr['pStnk'] = $pStnk2;
            $arr['pFlag2'] = 'Y';
        } 
        else if ($pAktif == 3) {    //JIKA PILIHAN ADALAH MOBIL 3
            $pParkirType = $pParkirType3;
            $pPlat = $pPlat3;
            $pStnk = $pStnk3;
            $pFlag3 = 'Y';
            $arr['pParkirType'] = $pParkirType3;
            $arr['pPlat'] = $pPlat3;
            $arr['pStnk'] = $pStnk3;
            $arr['pFlag3'] = 'Y';
        } 
        else {  //JIKA PILIHAN ADALAH MOTOR
            $pPlat = $pPlat4;
            $pStnk = $pStnk4;
            $pFlag4 = 'Y';
            $arr['pPlat'] = $pPlat4;
            $arr['pStnk'] = $pStnk4;
            $arr['pFlag4'] = 'Y';
        }
        
        //var_dump($arr); exit;
        if (empty($pParkirdId)) {   //JIKA REQUESTNO KOSONG, ARTINYA MENU ADD/BUKAN MENU EDIT
            /*
            if ($_FILES["file"]["error"] > 0) {
                if ($_FILES["file"]["error"] <> 4)
                    echo "Error: " . $_FILES["file"]["error"] . "<br />";
            } 
            else {
                $qryz = "select max(parkird_filename) xx from fm_parkir_det where lower(parkird_filename) like 'park_%'";
                $DB4->parse($qryz);
                $DB4->execute();
                $fn1 = ($a = $DB4->nextrow()) ? $a['XX'] : '';
                $fn = preg_match('/^park_(\d{5})/', $fn1, $match) ? str_pad(++$match[1], 5, '0', STR_PAD_LEFT) : '00001';
                $fext = ($x = strrpos($_FILES["file"]["name"], '.')) !== false ? substr($_FILES["file"]["name"], $x) : '';
                $fext = strtolower($fext);
                $fname = "park_$fn$fext";
                $fdest = "upload/$fname";
                unset($fn, $fext);
        
                $res_upload = move_uploaded_file($_FILES["file"]["tmp_name"], $fdest);
                if ($res_upload) {
                    chmod($fdest, 0644);
                } else {
                    $fname = '';
                    $filename = '';
                }
            }
        
            $qry1 = "select max(to_number(substr(parkird_id,1,5),'99999')) parkird_id_old, rtrim(to_char(sysdate,'RM')) romawi from fm_parkir_det";
            $DB1->parse($qry1);
            $DB1->execute();
            if ($a = $DB1->nextrow()) {
                $cParkirdIdOld = $a["PARKIRD_ID_OLD"];
                $cRomawi = $a["ROMAWI"];
                $cParkirdIdNew = $cParkirdIdOld + 1;
            }
        
        
            $qry2 = "select lpad($cParkirdIdNew,5,0)||'/PARK/$cRomawi/'||TO_CHAR(SYSDATE,'YYYY') parkird_id from dual";
            $DB2->parse($qry2);
            $DB2->execute();
            if ($a = $DB2->nextrow()) {
                $cParkirdId = $a["PARKIRD_ID"];
            }
        
            $filename = str_replace("'", "x", $filename);
        
            $stmt1 = "insert into fm_parkir_det(parkird_id, parkird_nik, parkird_untuk_nik, parkird_use_by, parkird_type, parkird_plat, parkird_stnk,
        										   parkird_type_1, parkird_plat_1, parkird_stnk_1, parkird_flag_1,
        										   parkird_type_2, parkird_plat_2, parkird_stnk_2, parkird_flag_2,
        										   parkird_type_3, parkird_plat_3, parkird_stnk_3, parkird_flag_3,
        										   parkird_type_4, parkird_plat_4, parkird_stnk_4, parkird_flag_4,
        										   parkird_description, parkird_atasan_nik, parkird_reference, parkird_date,
        										   parkird_file, parkird_filetype, parkird_size, parkird_status, parkird_filename) " .
                    " values ('$cParkirdId','$pNik','$pNikFor','$pStatusFor','$pParkirType','$pPlat','$pStnk',
        										  '$pParkirType1','$pPlat1','$pStnk1','$pFlag1',
        										  '$pParkirType2','$pPlat2','$pStnk2','$pFlag2',
        										  '$pParkirType3','$pPlat3','$pStnk3','$pFlag3',
        										  '$pParkirType4','$pPlat4','$pStnk4','$pFlag4',
        										  '$pDescription','$pAtasanNik','$pReqId',sysdate,
        										  '$filename','$filetype','$filesize','Y','$fname')";
            $DB3->parse($stmt1);
            $DB3->execute();
        
            $stmt2 = "update fm_req_det set req_det_app = 'Y' where req_id='$pReqId' and req_det_id= '$pReqDetId'";
            $DB3->parse($stmt2);
            $DB3->execute();
        
            $msg = "FM : Order No $cParkirdId telah berhasil, untuk Proses selanjutnya menunggu Approval dari atasan anda $vAtasanName.";
            $msgatasan = "FM : Order No $cParkirdId membutuhkan approval anda.";
        
            // Start Sms
            // Sms to User
            $msisdn = dbora_getgamsisdn($pNikFor);
            send_sms($msisdn, $msg);
            //End Sms User
            // Sms to Atasan
            $msisdnatasan = dbora_getgamsisdn($pAtasanNik);
            send_sms($msisdnatasan, $msgatasan);
            //End Sms Atasan
            //End Sms user
            //End Sms
        
            echo "<script>
        			location.href=\"room_notification.php?pMessage=$msg\";
        		      </script>";
            */
        } 
        else {  //MERUPAKAN MENU EDIT, PERHATIKAN SAJA BAGIAN INI
            if ($_FILES["file"]["error"] > 0) { //JIKA FILE UPLOAD ERROR
                if ($_FILES["file"]["error"] <> 4)
                    echo "Error: " . $_FILES["file"]["error"] . "<br />";
            } 
            else { //JIKA UPLOAD TIDAK ERROR
                //SELECT FM_PARKIR_DET
                $prkSelect1=$this->sGlobal_model->prkSelect1();
                $fn1='';
                foreach($prkSelect1 as $a){
                        $fn1=$a['XX'];
                }
                //$fn1 = ($a = $DB4->nextrow()) ? $a['XX'] : '';
                $fn = preg_match('/^park_(\d{5})/', $fn1, $match) ? str_pad(++$match[1], 5, '0', STR_PAD_LEFT) : '00001';
                $fext = ($x = strrpos($_FILES["file"]["name"], '.')) !== false ? substr($_FILES["file"]["name"], $x) : '';
                $fext = strtolower($fext);
                $fname = "park_$fn$fext";
                $arr['fname']=$fname;
                $fdest = "upload/$fname";
                
                //echo $fname; exit;
                unset($fn, $fext);
        
                $res_upload = move_uploaded_file($_FILES["file"]["tmp_name"], $fdest);
                if ($res_upload) {
                    chmod($fdest, 0644);
                } 
                else {
                    $fname = '';
                    $filename = '';
                }
            }
            
            //exit;
            $filename = str_replace("'", "x", $filename);
        
            if (empty($pStatus)) { //JIKA STATUS EMPTTY, UNTUK MENU EDIT SUDAH PASTI EMPTY
                if (!empty($filename)) { //JIKA UPLOAD FILE BARU, ARTINYA MENGUBAH FILE UPLOAD SEBELUMNYA
                    //UPDATE FM_PARKIR_DET
                    $prkUpdate1=$this->sGlobal_model->prkUpdate1($arr);
                } 
                else { //JIKA TIDAK ADA FILE UPLOAD YANG BARU, MAKA TIDAK PERLU MENAMBAHKAN UPLOAD DIR KE DATABASE
                    //UPDATE FM_PARKIR_DET
                    $prkUpdate1=$this->sGlobal_model->prkUpdate2($arr);
                }
                ?>
                <script>
                    top.location.href="<?php echo site_url("/search_global/search_global");?>";
                </script>
                <?php 
            } //JIKA ADA STATUSNYA
            else { /*
                $stmt1 = "update fm_parkir_det set parkird_status='N', parkird_date=sysdate where parkird_id = '$pParkirdId' ";
                $DB3->parse($stmt1);
                $DB3->execute();
        
                $filename = str_replace("'", "x", $filename);
        
                $stmt2 = "insert into fm_parkir_det(parkird_nik, parkird_stnk, parkird_plat, parkird_description, parkir_id, parkird_atasan_nik, parkird_use_by, parkird_untuk_nik, parkird_reference, parkird_date, parkird_file, parkird_type, parkird_size, parkird_status) " .
                        " values ('$pNik','$pStnk','$pPlat','$pDescription','$pParkirId','$pAtasanNik', '$pStatusFor', '$pNikFor', '$pReqId',sysdate,'$filename','$filetype','$filesize','Y')";
                $DB3->parse($stmt2);
                $DB3->execute();
                */
            }
        }

    }
    //PARKIR EDIT SAVE===========================END=====================================================
    
    //REPAIRMAINTENANCE EDIT SAVE===========================START===================================================
    public function edit_RmSave(){
        $pRmID			=  $_POST['pRmID'];
        $pCType			=  $_POST['pCType'];
    	$pRmType 		=  $_POST['pRmType'];
    	$pRmCategory 	=  $_POST['pRmCategory'];
    	$pRmDesc 		=  str_replace("'", "''", $_POST['pRmDesc']);
    	$pRmSerial 		=  $_POST['pRmSerial'];
    	$pAtasanNik	    =  $_POST['pAtasanNik'];
    	$pRmFloor 		=  $_POST['pRmFloor'];
    	$pRmDate1 		=  $_POST['pRmDate1'];
    	$pRmDate2 		=  $_POST['pRmDate2'];
    	$pNikFor		=  $_POST['pNikFor'];
        
        $arr['pRmID']			=  $_POST['pRmID'];
        $arr['pCType']			=  $_POST['pCType'];
    	$arr['pRmType'] 		=  $_POST['pRmType'];
    	$arr['pRmCategory'] 	=  $_POST['pRmCategory'];
    	$arr['pRmDesc'] 		=  str_replace("'", "''", $_POST['pRmDesc']);
    	$arr['pRmSerial'] 		=  $_POST['pRmSerial'];
    	$arr['pAtasanNik']	    =  $_POST['pAtasanNik'];
    	$arr['pRmFloor'] 		=  $_POST['pRmFloor'];
    	$arr['pRmDate1'] 		=  $_POST['pRmDate1'];
    	$arr['pRmDate2'] 		=  $_POST['pRmDate2'];
    	$arr['pNikFor']		    =  $_POST['pNikFor'];
        
        //var_dump($arr); exit;
    	//$msg = "";
    	//$vAtasanName		= dbora_getname($pTrAtasanNik	);
    
    	//JIKA RMID KOSONG, ARTINYA BUKAN MENU EDIT, TAPI MENU ADD JD TINGGALIN AJA
    	if(empty($pRmID)){/*
    		$qry1 = "select max(to_number(substr(rm_id,1,5),'99999')) rm_id_old, rtrim(to_char(sysdate,'RM')) romawi from fm_rm";
    		$DB1->parse($qry1);
    		$DB1->execute();
    		if($a=$DB1->nextrow()){
    			$cRmIdOld = $a["RM_ID_OLD"];	
    			$cRomawi  = $a["ROMAWI"];	
    			$cRmIdNew = $cRmIdOld +1;
    		}
    					
    		$qry2 = "select lpad($cRmIdNew,5,0)||'/DOC/$cRomawi/'||TO_CHAR(SYSDATE,'YYYY') rm_id from dual";
    		$DB1->parse($qry2);
    		$DB1->execute();
    		if($a=$DB1->nextrow()){
    			$cRmId = $a["RM_ID"];	
    		}
    					
    		$stmt	=	" insert into fm_rm(rm_id, rm_nip, rm_description, rm_suite, rm_date,
    									    rm_create_by, rm_create_date, rm_serial, rm_floor,
    									   rm_type, rm_category, rm_delivery, rm_return, RM_ATASAN_ID, RM_UNTUK_NIK) ".
    					" values ('$cRmId','$nik','$pRmDesc','$pRmSuite',trunc(sysdate), '$nik', trunc(sysdate), '$pRmSerial', '$pRmFloor',
    									   '$pRmType','$pRmCategory',to_date('$pRmDate1','dd/mm/yyyy'), to_date('$pRmDate2','dd/mm/yyyy'),
    									   '$pTrAtasanNik', '$pNikFor')";
    	
    		$DB2->parse($stmt);
    		$DB2->execute();
    		
    		$msg = "FM : Order No $cRmId telah berhasil, untuk Proses selanjutnya menunggu Approval dari atasan anda $vAtasanName.";
    		$msgatasan = "FM : Order No $cRmId membutuhkan approval anda.";
    	
    		// Start Sms
    			
    		// Sms to User
    		$msisdn = dbora_getgamsisdn($pNikFor);
    		send_sms($msisdn, $msg);
    		//End Sms User
    	
    		// Sms to Atasan
    		$msisdnatasan = dbora_getgamsisdn($pTrAtasanNik);
    		send_sms($msisdnatasan, $msgatasan);
    		//End Sms Atasan
    	
    		//End Sms user
    			
    		//End Sms
    	
    		echo "<script>
    			location.href=\"room_notification.php?pMessage=$msg\";
    		  </script>";
    
    		*/
    	}
        else { //MENU EDIT, MULAILAH DARI SINI
            $rmUpdate1=$this->sGlobal_model->rmUpdate1($arr);
    	}
    }
    //REPAIRMAINTENANCE EDIT SAVE===========================END=====================================================
    //REQUEST GA EDIT SAVE===========================START===================================================
    public function edit_gaSave(){
        $pReqId    			=  $_POST['pReqId'];
    	$pReqDescription    =  str_replace("'", "''", $_POST['pReqDescription']);
    	$pReqInfoHrd    	=  $_POST['pReqInfoHrd'];
    	$pNik    			=  $_POST['pNik'];
    	$pNikFor    		=  $_POST['pNikFor'];
    	$pAtasanNik    		=  $_POST['pAtasanNik'];
    	$pAtasanName    	=  $_POST['pAtasanName'];
    	$cJob  				=  $_POST['pJobPosition']; 	
        
        $arr['pReqId']    		=  $_POST['pReqId'];
    	$arr['pReqDescription'] =  str_replace("'", "''", $_POST['pReqDescription']);
    	$arr['pReqInfoHrd']    	=  $_POST['pReqInfoHrd'];
    	$arr['pNik']    		=  $_POST['pNik'];
    	$arr['pNikFor']    		=  $_POST['pNikFor'];
    	$arr['pAtasanNik']    	=  $_POST['pAtasanNik'];
    	$arr['pAtasanName']    	=  $_POST['pAtasanName'];
    	$arr['cJob']  			=  $_POST['pJobPosition']; 
        //var_dump($arr); exit;
        if(!empty($pReqId)){
    		if(!empty($pFloor) && !empty($pRoomFloor)){ //BUKAN MENUNYA, KARNA PFLOOR EMANG KOSONG
                //$stmt1="update fm_req_head set req_description='$pReqDescription', req_info_hrd='$pReqInfoHrd',  req_atasan_nik='$pAtasanNik', req_date=sysdate, req_floor='$pRoomFloor', req_rbf_id='$pRoomFloor' where req_id='$pReqId' ";
    		}
            else{
                //UPDATE FM_REQ_HEAD    
                $reqUpdate1=$this->sGlobal_model->reqUpdate1($arr);
		    }
	    }
        

    }
    //REQUEST GA EDIT SAVE===========================END=====================================================
    //MAILLING ROOM EDIT SAVE===========================START===================================================
    public function edit_mailSave(){
        //$pDmKurir 		=  $_POST['pDmKurir'];
    	$pDmTujuan 		=  $_POST['pDmTujuan'];
    	$pDmType 		=  $_POST['pDmType'];
    	$pDmDesc 		=  $_POST['pDmDesc'];
    	$pDmBerat		=  $_POST['pDmBerat'];
    	$pAtasanNik		=  $_POST['pAtasanNik'];
    	$pDmRegional	=  $_POST['pDmRegional'];
    	$pDmLokasi		=  $_POST['pDmLokasi'];
    	$pDmFloor		=  $_POST['pDmFloor'];
    	$pDmCategory	=  $_POST['pDmCategory'];
    	$pDmTime		=  $_POST['pDmTime'];
    	$pJasaKurir		=  $_POST['pJasaKurir'];
    	$pDmrId			=  $_POST['pDmrId'];
        $pCType			=  $_POST['pCType'];
        
        $arr['pDmTujuan'] 		=  $_POST['pDmTujuan'];
    	$arr['pDmType'] 		=  $_POST['pDmType'];
    	$arr['pDmDesc'] 		=  $_POST['pDmDesc'];
    	$arr['pDmBerat']		=  $_POST['pDmBerat'];
    	$arr['pAtasanNik']		=  $_POST['pAtasanNik'];
        $arr['pAtasanName']		=  $_POST['pAtasanName'];
    	$arr['pDmRegional']	    =  $_POST['pDmRegional'];
    	$arr['pDmLokasi']		=  $_POST['pDmLokasi'];
    	$arr['pDmFloor']		=  $_POST['pDmFloor'];
    	$arr['pDmCategory']	    =  $_POST['pDmCategory'];
    	$arr['pDmTime']		    =  $_POST['pDmTime'];
    	$arr['pJasaKurir']		=  $_POST['pJasaKurir'];
    	$arr['pDmrId']			=  $_POST['pDmrId'];
        $arr['pCType']			=  $_POST['pCType'];
        //var_dump($arr); exit;
        $mailUpdate1=$this->sGlobal_model->mailUpdate1($arr);
    }
    //MAILLING ROOM EDIT SAVE===========================END=====================================================
    //MEETING ROOM EDIT SAVE===========================START===================================================
    public function edit_meetSave(){
        $pCType			=  $_POST['pCType'];
        $vRoomId		=  $_POST['vRoomId'];
    	$pStrHour		=  $_POST['pStrHour'];
    	$pEndHour		=  $_POST['pEndHour'];
    	$pAction		=  $_POST['pAction'];
        
        $arr['pCType']		=  $_POST['pCType'];
        $arr['vRoomId']		=  $_POST['vRoomId'];
    	$arr['pStrHour']	=  $_POST['pStrHour'];
    	$arr['pEndHour']	=  $_POST['pEndHour'];
    	$arr['pAction']		=  $_POST['pAction'];
        
        //var_dump($arr); exit;
        if($pAction == 'Y'){
            $meetUpdate1=$this->sGlobal_model->meetUpdate1($arr);
    	}
        else {
            $meetDelete=$this->sGlobal_model->meetDelete1($vRoomId);
            $meetDelete2=$this->sGlobal_model->meetDelete2($vRoomId);
            $meetDelete3=$this->sGlobal_model->meetDelete3($vRoomId);
    	}
    }
    //MEETING ROOM EDIT SAVE===========================END=====================================================
    //SARAN KELUHAN EDIT SAVE===========================START===================================================
    public function edit_sarKelSave(){
        $pCType			    =  $_POST['pCType'];
        $pPoboxId    		=  $_POST['pPoboxId'];
    	$pNik    			=  $_POST['pNik'];
    	$pType    			=  $_POST['pType'];
    	$pCriteria    		=  $_POST['pCriteria'];
    	$pSubject    		=  $_POST['pSubject'];
    	$pDescription  		=  $_POST['pDescription'];
    	$pAtasanNik    		=  $_POST['pAtasanNik'];
    	$pAtasanNama    	=  $_POST['pAtasanNama'];
    	$pNikFor    		=  $_POST['pNikFor'];
    	$pRelatedTo    		=  $_POST['pRelatedTo'];
        
        $arr['pCType']			    =  $_POST['pCType'];
        $arr['pPoboxId']    		=  $_POST['pPoboxId'];
    	$arr['pNik']    			=  $_POST['pNik'];
    	$arr['pType']    			=  $_POST['pType'];
    	$arr['pCriteria']    		=  $_POST['pCriteria'];
    	$arr['pSubject']    		=  $_POST['pSubject'];
    	$arr['pDescription']  		=  $_POST['pDescription'];
    	$arr['pAtasanNik']    		=  $_POST['pAtasanNik'];
    	$arr['pAtasanNama']    	    =  $_POST['pAtasanNama'];
    	$arr['pNikFor']    		    =  $_POST['pNikFor'];
    	$arr['pRelatedTo']    		=  $_POST['pRelatedTo'];
        
        //var_dump($arr); exit;
        $sarKelUpdate1=$this->sGlobal_model->sarKelUpdate1($arr);
    }
    //SARAN KELUHAN EDIT SAVE===========================END=====================================================
    //ORDER EQUIPMENT EDIT SAVE===========================START===================================================
    public function edit_orderSave(){
        $pCType			    =  $_POST['pCType'];
        $pOrderId    		=  $_POST['pOrderId'];
        $pHrId   			=  $_POST['pHrId'];
        $pDesc    			=  $_POST['pDesc'];
        $pTglAwal    		=  $_POST['pTglAwal'];
        $pTglAkhir    		=  $_POST['pTglAkhir'];
        $pOrderFor    		=  $_POST['pOrderFor'];
        $pAtasanId    	    =  $_POST['pAtasanId'];
        $pAtasanApp   		=  $_POST['pAtasanApp'];
        $pJumlahItem    	=  $_POST['pJumlahItem'];
        $pItemCek    		=  $_POST['pItemCek'];
        $pItemId    		=  $_POST['pItemId'];
        $pItemName    	    =  $_POST['pItemName'];
        $pItemQty   		=  $_POST['pItemQty'];
        $pOtherId    	    =  $_POST['pOtherId'];
        $pOtherName   		=  $_POST['pOtherName'];
        
        
        $arr['pCType']			    =  $_POST['pCType'];
        $arr['pOrderId']    		=  $_POST['pOrderId'];
        $arr['pHrId']   			=  $_POST['pHrId'];
        $arr['pDesc']    			=  $_POST['pDesc'];
        $arr['pTglAwal']    		=  $_POST['pTglAwal'];
        $arr['pTglAkhir']    		=  $_POST['pTglAkhir'];
        $arr['pOrderFor']    		=  $_POST['pOrderFor'];
        $arr['pAtasanId']    	    =  $_POST['pAtasanId'];
        $arr['pAtasanApp']   		=  $_POST['pAtasanApp'];
        $arr['pJumlahItem']    	    =  $_POST['pJumlahItem'];
        $arr['pItemCek']    		=  $_POST['pItemCek'];
        $arr['pItemId']    	    	=  $_POST['pItemId'];
        $arr['pItemName']    	    =  $_POST['pItemName'];
        $arr['pItemQty']       		=  $_POST['pItemQty'];
        $arr['pOtherId']    	    =  $_POST['pOtherId'];
        $arr['pOtherName']   		=  $_POST['pOtherName'];
        
        //var_dump($arr); exit;
        
        //var_dump($arr); exit;
        $orderUpdate1=$this->sGlobal_model->orderUpdate1($arr);
        for($x=0;$x<$pJumlahItem;$x++){
            if($pItemCek[$x]=="Y"){ //Jika tercentang
                $getDetail3=$this->sGlobal_model->getDetailEditOrder3($pOrderId,$pItemId[$x]);
                foreach($getDetail3 as $a){
                    $cnt = $a['CNT'];
                    $sum = $a['ORDER_DET_QTY']; 
                }
                if(empty($cnt)){ //Jika data Item ke-x belum masuk dalam order, maka INSERT BARU
                    $orderSelect1=$this->sGlobal_model->orderSelect1(); //ambil nilai terakhir dari order_det_id
                    foreach($orderSelect1 as $no){
                        $nextNomer=$no['ORDER_DET_ID']+1;
                    }
                    if(!empty($pItemQty[$x])){ //jika quantity tidak kosong, maka insert order item baru
                        $orderInsertItem=$this->sGlobal_model->orderInsertItem($pOrderId,$pItemId[$x],$pItemName[$x],$pItemQty[$x],$nextNomer);    
                    }
                }
                else{ //selain itu UPDATE
                    if(!empty($pItemQty[$x])){ //jika quantity tidak kosong, maka update order item dengan quantity
                        $orderUpdateItem=$this->sGlobal_model->orderUpdateItem($pOrderId,$pItemId[$x],$pItemQty[$x]);   
                    }
                    else{ //update order item dengan quantity 0
                        $orderUpdateItem=$this->sGlobal_model->orderUpdateItem($pOrderId,$pItemId[$x],'0'); 
                    }
                }
            }    
            else{ //Jika Tidak dicentang
                $getDetail3=$this->sGlobal_model->getDetailEditOrder3($pOrderId,$pItemId[$x]);
                foreach($getDetail3 as $a){
                    $cnt = $a['CNT'];
                    $sum = $a['ORDER_DET_QTY']; 
                }
                if(!empty($cnt)){ //Jika data Item ke-x sudah ada dalam order, maka UPDATE DENGAN QUANTITY 0, jangan di delete
                    $orderUpdateItem=$this->sGlobal_model->orderUpdateItem($pOrderId,$pItemId[$x],'0'); 
                }
            }
        }
        $orderUpdateOther=$this->sGlobal_model->orderUpdateItemOther($pOrderId,$pOtherId,$pOtherName);
    }
    //ORDER EQUIPMENT EDIT SAVE===========================END=====================================================
    
    
    
    //------------------------------------------------PRINT START------------------------------------------------------------------
    function print_req(){
        $data['cRequestNo']=$this->input->post('cRequestNo');
        $data['cType']=$this->input->post('cType');
        $data['cTab']=$this->input->post('cTab');
        $cRequestNo=$data['cRequestNo'];
        $cType=$data['cType'];
        $cTab=$data['cTab'];
        //ambil session
        $CI =& get_instance();
        $data['sesName']=$CI->session->userdata('login')['name'];
        $data['sesJob']=$CI->session->userdata('login')['job'];
        $data['sesNik']=$CI->session->userdata('login')['nik'];
		$data['sesJobPosition']=$CI->session->userdata('login')['jobposition'];
        $data['sesOrg']=$CI->session->userdata('login')['org'];
        
        switch($cTab){
            case 'saranaKerja':
                switch($cType){
                    case 'REQUEST GA':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintReq($cRequestNo);
                        $this->load->view('search_global/print_srnKrjReq',$data);
                        break;
                    case 'OVERTIME':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintOvt($cRequestNo);
                        foreach($data['getDetail'] as $z){
                            $zUntukNik   		= $z["SO_UNTUK_NIK"];
                        }
                        $data['getDetailPhone']=$this->sGlobal_model->getDetailPrintOvtPhone($zUntukNik);
                        $data['getDetailName']=$this->sGlobal_model->getDetailPrintOvtName($cRequestNo);
                        $this->load->view('search_global/print_srnKrjOvt',$data);
                        break;
                    case 'REPAIR & MAINTENANCE':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintRm($cRequestNo);
                        $this->load->view('search_global/print_srnKrjRm',$data);
                        break;
                    case 'SURAT IJIN KERJA':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintSik($cRequestNo);
                        foreach($data['getDetail'] as $a){
                            $aUntukNik   	= $a["SIK_UNTUK_NIK"];
                        }
                        $data['getDetailPhone']=$this->sGlobal_model->getDetailPrintSikPhone($aUntukNik);
                        $data['getDetailName']=$this->sGlobal_model->getDetailPrintSikName($cRequestNo);
                        $this->load->view('search_global/print_srnKrjSik',$data);
                        break;
                    case 'ACCESS CONTROL':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintAcc($cRequestNo);
                        $data['getFloor']=$this->sGlobal_model->getDetailPrintAccFloor($cRequestNo);
                        $data['getTelp']=$this->sGlobal_model->getDetailPrintAccTelp($cRequestNo);
                        $this->load->view('search_global/print_srnKrjAcc',$data);
                        break;
                    case 'LOT PARKIR':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintPrk($cRequestNo);
                        $this->load->view('search_global/print_srnKrjPrk',$data);
                        break;
                }
                break;
            case 'publicRoom':
                switch($cType){
                    case 'MEETING ROOM': 
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintMeet($cRequestNo);
                        $data['getDetail2']=$this->sGlobal_model->getDetailPrintMeet2($cRequestNo);
                        $this->load->view('search_global/print_pubRomMeet',$data);
                        break;
                    case 'MAILLING ROOM':
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintMail($cRequestNo);
                        $this->load->view('search_global/print_pubRomMail',$data);
                        break;    
                } 
                break;
            case 'services':
                switch($cType){
                    case 'PAGING INFO': //hanya 1 data tahun 2009, tidak terdapat menu edit
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintPag($cRequestNo);
                        $this->load->view('search_global/print_servPag',$data);
                        break;
                    case 'SARAN & KELUHAN':  
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintSarKel($cRequestNo);
                        foreach($data['getDetail'] as $a){
                            $aPoboxUntukNik  	= $a["POBOX_UNTUK_NIK"];
                            $aTypeId  			= $a["TYPE_ID"];
                        }
                        $data['getDetailPhone']=$this->sGlobal_model->getDetailPrintSarKelPhone($aPoboxUntukNik);
                        $data['getDetailCriteria']=$this->sGlobal_model->getDetailPrintSarKelCrit($aTypeId);
                        $this->load->view('search_global/print_servSarKel',$data);
                        break;
                    case 'ORDER EQUIPMENT': 
                        $data['getDetail']=$this->sGlobal_model->getDetailPrintOrder($cRequestNo);
                        foreach($data['getDetail'] as $a){
                            $aOrderFor   		= $a["ORDER_FOR"];
                        }
                        $data['getDetailPhone']=$this->sGlobal_model->getDetailPrintOrderPhone($aOrderFor);
                        $data['getDetailName']=$this->sGlobal_model->getDetailPrintOrderName($cRequestNo);
                        $this->load->view('search_global/print_servOrder',$data);
                        break;
                    case 'TRAFFIC': //no data 
                        break;         
                } 
                break;           
        }
    }
    //------------------------------------------------PRINT END--------------------------------------------------------------------
    
    function globals_rel_SearchGlobal()
	{
		$Rel_Name[] = SearchDetailRel($this->security->xss_clean($this->input->post('SearchName')));
		foreach($Rel_Name AS $Rel_Name =>$keyVal)
		{
			$data['Show_Name'] = $keyVal['arr_Name'];
		}
		echo json_encode($data);
	}
    function globals_nik_SearchGlobal()
	{
		$Emp_Name[] = SearchDetailEmpGlobal($this->security->xss_clean($this->input->post('SearchName')));
		foreach($Emp_Name AS $Emp_Name =>$keyVal)
		{
			$data['Show_Name'] = $keyVal['arr_Name'];
		}
		echo json_encode($data);
	}
    function globals_ven_Search()
	{
	   $Ven_Name[] = SearchDetailVen($this->security->xss_clean($this->input->post('SearchName'),$this->input->post('nilai')));
        //$Ven_Name[] = SearchDetailVen($this->security->xss_clean($this->input->post('SearchName')));
		foreach($Ven_Name AS $Ven_Name =>$keyVal)
		{
			$data['Show_Name'] = $keyVal['arr_Name'];
		}
        //echo $this->input->post('SearchName'); exit();
		echo json_encode($data);
	}
	
    function globals_rel_detail()
	{
		$data['DetailRel'] = putDetailRel($this->security->xss_clean($this->input->post('id')));
		echo json_encode($data);
	}
	function globals_nik_detail()
	{
		$data['DetailEmp'] = putDetailEmp($this->security->xss_clean($this->input->post('id')));
		echo json_encode($data);
	}
    function globals_floor_detail()
	{
		$data['DetailFloor'] = putDetailFloor($this->security->xss_clean($this->input->post('id')));
		echo json_encode($data);
	}
    function globals_ven_detail()
	{
		$data['DetailVen'] = putDetailVen($this->security->xss_clean($this->input->post('id')));
		echo json_encode($data);
	}
    function getCategoryFromType(){
        $id=$this->input->post('id');
		$this->load->model('sGlobal_model');
		$data['getCategory'] = $this->sGlobal_model->getCategoryFromType($id);
		//var_dump($data['city']); exit;
		$this->load->view('search_global/showCategory',$data);
    }
    function getFloorFromCategory(){
        $typid=$this->input->post('typId');
        $id=$this->input->post('id');
		$this->load->model('sGlobal_model');
		$data['getCategory'] = $this->sGlobal_model->getCategoryFromType($typid,$id);
		//var_dump($data['city']); exit;
		$this->load->view('search_global/showFloor',$data);
    }
}
?>